Richienb / audic

Play some audio.
MIT License
68 stars 9 forks source link

Audio always looping if vlc loop is set to true #19

Closed kennarddh closed 1 year ago

kennarddh commented 1 year ago

image

If loop is set to true in vlc audio will always be looped even when

const audic = new Audic(path)

audic.loop = false
kennarddh commented 1 year ago

I can solve this with listening to timeupdate event

const audic = new Audic(path)

audic.loop = false

await audic.play()

audic.addEventListener('timeupdate', () => {
  if (audic.currentTime === audic.duration - 1) {
    audic.destroy()
  }
})
yuyaryshev commented 1 year ago

Workaround above doesn't seem to work stable - sometimes it repeats small part of sound just before audic.destroy().

A better workaround:

export async function yPlaySoundFile(filePath: string) {
    const Audic = (await import("audic")).default;

    const audic = new Audic(filePath);
    audic.loop = false;

    // Fix to the library
    void (async () => {
        const vlc = await (audic as any)._vlc;

        const { repeat, loop } = await vlc.info();

        if (loop) {
            await vlc.command("pl_loop");
        }

        if (repeat) {
            await vlc.command("pl_repeat");
        }
    })();
    //

    audic.addEventListener("ended", () => {
        audic.destroy();
    });
    await audic.play();
}

Pull request here: https://github.com/Richienb/audic/pull/22

kennarddh commented 1 year ago

Has the fix been released yet?

Richienb commented 1 year ago

It has now been. v3.0.2