Open Klemen1337 opened 7 years ago
same problem here, but it only happens with some of my mp3 files, some files work just fine.
Also mplayer itself is not the problem... when i run mplayer my.mp3
everything works fine with all files.
Wow, I thought something wrong with my code. It's happen after I set timeout. Do you guys solve this problem?
@Isht nope, I built some nasty workaround, which reads the length of the audio file and stops playing the file after that time.
Here's my workaround code
// TODO remove this:
let opts;
import { AudioPlayer } from "../audio-player";
var player = require("play-sound")(
(opts = { player: "./mplayer/mplayer.exe" })
);
var mp3Duration = require("mp3-duration");
import { promisify } from "util";
import sleep from "../../util/sleep";
// TODO: Promisify or totally replace the audio player
export class Mp3Player implements AudioPlayer {
async play(filePath: string): Promise<void> {
const getDuration = promisify(mp3Duration);
const duration = await getDuration(filePath); // audio duration in seconds
let audio = player.play(
filePath,
{ "./mplayer/mplayer.exe": ["-ao", "sdl"] },
(err: Error) => {
if (err) throw err;
}
);
await sleep(duration * 1500); // workaround's workaround, because killing the audio exactly after it's length is to early (probably because it only starts playing after some delay)
audio.kill();
}
}
@Waog This question might be unrelated to the thread, but how come are you using both require and import statements, without importing require itself (assuming that you have the type field as module at the package.json file)
When I play a sound it keeps looping and it never ends... Dose anyone have the same problem?