pixijs / sound

WebAudio API playback library, with filters. Modern audio playback for modern browsers.
https://pixijs.io/sound/examples/
MIT License
409 stars 67 forks source link

Pause/Resume Bug in PixiJS Sound v4.4.1 Causes Unexpected Spritemap Behavior #269

Open nizamiza opened 3 months ago

nizamiza commented 3 months ago

Description

PixiJS Sound v4.4.1 has a pause/resume issue when working with spritemaps. Pausing and resuming a sound causes unexpected behavior, such as jumping to the next sound in the spritemap instead of restarting the current sound.

I believe that this issue arises because the internal _elapsed time scales according to the entire spritemap, and the AudioBufferSourceNode API lacks native pause/resume functionality. The known workaround is to manually control the playbackRate property of the AudioBufferSourceNode.

Reproduction

I've created a repro repository here: https://github.com/nizamiza/pixi-sound-pause-resume-issue-repro

It has a detailed description of the issue, the use-case applied, and a an option to test the workaround as a well a fix for the elapsed time.

In the repro repository, the WebAudioNode instance is used to toggle paused state. I'm not 100% sure that this is an intended way. When you run the repro project, open it in your browser and follow the instructions to experience the problem.

Let me know if you need any additional info.

Packages info