sound icon indicating copy to clipboard operation
sound copied to clipboard

Check if sound is played

Open creyD opened this issue 4 years ago • 4 comments

I searched the documentation, but I can't seem to find any method/ state to check if a sound or any sound at all is currently playing. What I would like to do in my case would be to check whether a sound is played and if not, then to play it. And in another case check if any sound is played and then play a specific sound depending on the result.

creyD avatar Jul 22 '20 13:07 creyD

Each instance of Sound has an isPlaying property: https://pixijs.io/pixi-sound/docs/PIXI.sound.Sound.html#isPlaying

andrewstart avatar Jul 22 '20 13:07 andrewstart

Thank you for the quick response. I am looking for something a bit more general maybe on the Pixi.sound level, so that I don't have to check each and every sound asset in my "library" if it is currently playing.

creyD avatar Jul 22 '20 14:07 creyD

You could do something like this.

function isPlayingAny() {
    for (const alias in PIXI.sound._sounds) {
        if (PIXI.sound._sounds[alias].isPlaying()) {
            return true;
        }
    }
    return false;
}

Seems like a useful feature to add.

bigtimebuddy avatar Jul 22 '20 15:07 bigtimebuddy

Thanks for the advice! :)

creyD avatar Jul 25 '20 15:07 creyD