Sound loop stop working after switching window

Hi there,

in my game i use a sound manager for the background music.

Setup in game config

            callbacks: {
                preBoot: function (game) {
                  game.soundManagerGame = Phaser.Sound.SoundManagerCreator.create(game);
                    game.soundManagerGame.pauseOnBlur = false;
                  game.soundManagerMusic = Phaser.Sound.SoundManagerCreator.create(game);
                    game.soundManagerMusic.pauseOnBlur = false;
                  game.soundManagerUi = Phaser.Sound.SoundManagerCreator.create(game);
                    game.soundManagerUi.pauseOnBlur = false;
                }
              }

It works great als long as i dont unfocus the main window.
After switchen browser to other tab and back, it still works. Sometimes…
But after some loops (sometimes the next loop, sometimes it seems to loop twice before breaking) it stops playing the sound.

Other sounds (like click a button) still working…
I dont see any warning / error in logs that point out why not looping anymore…

If i than output the states of the sound and its manager, it looks something like this, pretending it is still playing!

The Sound:

currentMarker: null
detune: (...)
duration: 14.769251700680272
hasEnded: false
hasLooped: false
isPaused: false
isPlaying: true
key: "lobby_background"
loop: (...)
loopSource: AudioBufferSourceNode {buffer: AudioBuffer, playbackRate: AudioParam, detune: AudioParam, loop: false, loopStart: 0, …}
loopTime: 59.07700680272109
manager: initialize {context: AudioContext, masterMuteNode: GainNode, masterVolumeNode: GainNode, destination: GainNode, locked: false, …}
markers: {}
mute: (...)
muteNode: GainNode {gain: AudioParam, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 1, channelCount: 2, …}
pan: (...)
pannerNode: StereoPannerNode {pan: AudioParam, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 1, channelCount: 2, …}
pendingRemove: false
playTime: 44.307755102040815
rate: (...)
rateUpdates: [{…}]
seek: (...)
source: AudioBufferSourceNode {buffer: AudioBuffer, playbackRate: AudioParam, detune: AudioParam, loop: false, loopStart: 0, …}
startTime: 44.307755102040815
totalDuration: 14.769251700680272
totalRate: 1


The manager:
context: AudioContext {baseLatency: 0.01, destination: AudioDestinationNode, currentTime: 288.2409070294785, sampleRate: 44100, listener: AudioListener, …}
destination: GainNode {gain: AudioParam, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 1, channelCount: 2, …}
detune: (...)
game: initialize {config: initialize, renderer: initialize, domContainer: div, canvas: canvas, context: WebGLRenderingContext, …}
jsonCache: initialize {entries: initialize, events: o}
locked: false
masterMuteNode: GainNode {gain: AudioParam, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 1, channelCount: 2, …}
masterVolumeNode: GainNode {gain: AudioParam, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 1, channelCount: 2, …}
mute: (...)
pauseOnBlur: false
rate: (...)
sounds: [initialize]
unlocked: false

Any idea why it happens and how to prevent it? :slight_smile:

Check context.state.

this is audio manager context after stop playing the loop:

baseLatency: 0.01
currentTime: 171.078820861678
destination: AudioDestinationNode {maxChannelCount: 2, context: AudioContext, numberOfInputs: 1, numberOfOutputs: 0, channelCount: 2, …}
listener: AudioListener {positionX: AudioParam, positionY: AudioParam, positionZ: AudioParam, forwardX: AudioParam, forwardY: AudioParam, …}
onstatechange: null
sampleRate: 44100
state: "running"

So it seems it thinks it is still running… But in fact, i dont hear anything :wink: