Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling .stop() on a sound whilst the browser window is blurred does not actually stop the sound #258

Open
alandeg opened this issue Jan 11, 2024 · 6 comments · May be fixed by #270
Open

Comments

@alandeg
Copy link

alandeg commented Jan 11, 2024

The context of this issue is related to the auto-pause feature introduces in a recent version of this library.

Steps to reproduce:

  1. Start playing a sound
  2. Blur the window
  3. Something must stop the sound i.e. an event listener which calls .stop()
  4. Focus the window again
  5. Observe the sound continues playing when it should not

As a workaround you must disable the auto pause feature using
PIXI.sound.disableAutoPause = true;

Example:
https://stackblitz.com/edit/js-mhehrg?file=index.js

@alandeg alandeg changed the title Calling .stop() on a sound whilst the browser window is blurred does not fully stop the sound Calling .stop() on a sound whilst the browser window is blurred does not actually stop the sound Jan 11, 2024
@bigtimebuddy
Copy link
Member

Thanks for the detailed bug. That makes sense. Will look at it soon

@ericente
Copy link
Contributor

ericente commented May 2, 2024

I'm seeing this same issue, though my repro steps are slightly simpler

  1. call pauseAll()
  2. call stop() on a specific sound instance
  3. call resumeAll()

I believe what's happening is that when pause() is called on a sound, it's _internalStop() is getting called, which is nulling this._source, so when stop() gets called while the sound is already paused, it checks if this._source exists, it doesn't, and then nothing happens. I think if we were to emit the 'stop' event any time stop() gets called, regardless of whether _source exists, Sound should trigger _onComplete() and clean up any instances still in the _instances array.

I've only looked at the v4 code, but here's the instance stop:

if (this._source)
{
this._internalStop();
this.emit('stop');
}

and here's the _onComplete:

sound/src/Sound.ts

Lines 766 to 776 in a84c214

if (this._instances)
{
const index = this._instances.indexOf(instance);
if (index > -1)
{
this._instances.splice(index, 1);
}
this.isPlaying = this._instances.length > 0;
}
this._poolInstance(instance);

@ericente
Copy link
Contributor

ericente commented May 2, 2024

I'm having some issues creating a fork right now, but this snippet seems to have fixed this issue in sound v4 in my project:

import { webaudio } from '@pixi/sound';
webaudio.WebAudioInstance.prototype.stop = function(){
    if (this._source)
    {
        this._internalStop();
    }
    this.emit('stop');
}

@nicolasalt
Copy link

I'm having the same issue, is there an ETA for the fix? Version 5.2.3.

Thank you!

@CatchABus
Copy link

CatchABus commented Aug 21, 2024

I did some digging and problem seems to be lying in refreshPause calls.
@nicolasalt Can you try changes from PR #270 a few times locally? It might be a candidate for fixing the issue.

@nicolasalt
Copy link

I've tried but your PR is on top of pixi/sound v6.0 which depends on pixijs v8, while I'm using pixijs v7.2.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants