Skip to content

Commit

Permalink
The WebAudioSoundManager will now detect if the Audio Context enter…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
photonstorm committed Nov 22, 2022
1 parent ee2b5f5 commit 320317c
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/sound/webaudio/WebAudioSoundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
},

/**
Expand Down

0 comments on commit 320317c

Please sign in to comment.