From 320317c884a26589f4485c67c4c9033e4bbac059 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 22 Nov 2022 18:38:49 +0000 Subject: [PATCH] The `WebAudioSoundManager` will now detect if the Audio Context enters a 'suspended' or 'interrupted' state as part of its update loop and if so it'll try to resume the context. This can happen if you change or disable the audio device, such as plugging in headphones with built-in audio drivers then disconnecting them, or swapping tabs on iOS. Fix #5353 --- src/sound/webaudio/WebAudioSoundManager.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/sound/webaudio/WebAudioSoundManager.js b/src/sound/webaudio/WebAudioSoundManager.js index d04cc926b..5548afaa1 100644 --- a/src/sound/webaudio/WebAudioSoundManager.js +++ b/src/sound/webaudio/WebAudioSoundManager.js @@ -345,7 +345,7 @@ var WebAudioSoundManager = new Class({ { var context = this.context; - if ((context.state === 'suspended' || context.state === 'interrupted') && !this.locked) + if (context && !this.locked && (context.state === 'suspended' || context.state === 'interrupted')) { context.resume(); } @@ -367,13 +367,8 @@ var WebAudioSoundManager = new Class({ { BaseSoundManager.prototype.update.call(this, time, delta); - var context = this.context; - // Resume interrupted audio on iOS - if (context && context.state === 'interrupted') - { - context.resume(); - } + this.onFocus(); }, /**