Open nolanbarry opened 1 year ago
I managed to reproduce reliably on my machine with this snippet, not sure if it is only my machine or what:
import { playAudioFile } from "audic";
playAudioFile("not.mp3");
setTimeout(() => {
playAudioFile("not.mp3");
}, 5000);
The audio file is only 3 seconds
The issue probably resides here: https://github.com/Richienb/vlc/blob/45eedbf9bab5e8985e6b32f1d9217c3e8a368c0a/source/index.ts#L190 A possible cause could be that it tries to connect to vlc while it is still starting the server so it fails.
@Richienb using your vlc
library directly solves the problem for me (ignore ugly nesting):
import createVlc from "@richienb/vlc";
const vlc = await createVlc();
const play = () => vlc.command("in_play", { input: "not.mp3" });
play();
setTimeout(() => {
play();
setTimeout(() => {
vlc.kill();
}, 5000);
}, 5000);
The first setTimeout
in your example supports the hypothesis that the http request is being made too early in the codebase of audic.
Not sure how to fix it well, PR welcome.
I ended up creating my own VLC wrapper (needed video playback anyway), which uses a request queue to send requests only after a successful ping to VLC. That'd require changing how this library works in a big way so ditto on the no easy fix. Could perhaps just make the constructor private and add a static async function that returns the VLC instance once it's established that it is accepting connections?
The solution is to probably change the upstream library https://github.com/Richienb/vlc instead.
Occasionally when playing a sound I get the following error:
Running
vlc
in the command line (evenvlc --help
, which doesn't keep a process running in the foreground) and restarting the node process seems to fix it, but I'm wondering if there's a little more insight on what exactly is happening behind the scenes?