Sound.mute bug

Hi!

I have a method:

  private onSoundClick() {
    const mute = this.scene.sound.mute;
    this.scene.sound.setMute(!mute);

    this.soundBtn.setFrame(mute ? 'volume_on' : 'volume_off');
  }

But sound mute state change only one time, after that I must play any other sound for activate this method again and mute state changed

Have you tried

console.log('mute', mute);

in that function?

Which version of Phaser do you use?
How is the method activated?

Here is the function I use to implement a mute button.

// Initiate mute button
    muteButton.on('pointerup', () => {
        // If sound is already muted, unmute it
        if (this.sound.mute) {
            this.sound.mute = false;
            muteButton.setTexture('radioButtonRoundOff');
        }
        // Otherwise, mute the sound
        else {
            this.sound.mute = true;
            muteButton.setTexture('radioButtonRoundOn');
        }
    });

Sorry for the misunderstanding.

I have a button - which must mute/unmute the game, and method onClick:

  private onSoundClick() {
    const mute = this.scene.sound.mute;

    this.soundBtn.setFrame(mute ? 'volume_on' : 'volume_off');

    this.scene.sound.setMute(!mute);

    this.scene.sound.play('flip', { volume: 0 }); // hack for fix
  }

Without the last line, this method only works one time, after that mute state doesn’t change (only if another sound plays).

Phaser v3.60.0 (WebGL | Web Audio)

Yeap, mute state changed only one time, after that console.log show same value (false\true).
Mute state only if play one more sound, event silent

For anyone like me who find themselves here with the same problem – your scene.sound.mute state isn’t updating correctly – and unable to find a solution online, all I can tell you is Sprutnik’s hack fix does work.

I added a sound file that is like a few ms of silence and use scene.sound.play('silence', { volume: 0 }); in my mute function after calling scene.sound.setMute(bool) and for whatever reason the value updates as expected.

I can’t reproduce this in Phaser v3.80.1 and Web Audio.