Closed SBCGames closed 4 years ago
I think I can just resume the audio context for every game "focus" event.
I can also add a SoundManager#onStateChange signal, but I'm not sure it would be super useful by itself.
Here is a try at automatic resume: phaser-test.js.zip
Yes, this seems to work. Audio is resumed when returning from incoming call. Thanks 🥇 !
A bug in the API: all versions
Currently Phaser does not handle "interrupted" state of WebAudio context. At least on iOS it is easy to get into it - just interrupt running game with incoming call (I used Skype to simulate it on iPad). After return into game audio is not playing and debug.sound says, that Wab Audio is interrupted.
I found, that I can simply resume context like this in SoundManager.update():
I do not know, whether context state is changed immediatley, so I am using _interruptHandlingOn variable as lock to prevent calling resume multiple times. Lock is reset on Promise .then(). As it works with Promise returned by context.resume(), it may be problem if Promise is not supported.
There is possibility to use context.onstatechange instead of Promise, it looks like this: