Hi everyone,
I’m encountering an issue on iOS where audio playback stops and doesn’t automatically resume after the user:
- Minimizes the web browser and then brings it back into focus, or
- Locks and unlocks their device while the browser is open.
What I’ve tried:
Calling this.app.soundManager.context.resume() when the page regains visibility, however this consistently results in the following error after repeated use:
Attempted to resume the AudioContext on SoundManager.resume(), but it was rejected. InvalidStateError: Failed to start the audio device.
I’ve prepared a test scene to demonstrate the issue:
https://playcanvas.com/project/1447932/overview/audio-test
In the demo:
- Background music starts when the user clicks “Start” .
- Buttons to manually trigger SFX, call
context.resume(), andcontext.suspend(). - Three experimental scripts that attempt to auto-resume audio (all currently disabled due to errors).
Feel free to fork the project and enable them for testing.
Of these, the “Suspend & Resume” approach seemed most reliable, though it feels hacky and might break other things…
Steps to reproduce:
- Open the project on an iOS device and click “Start” (BGM should play).
- Minimize the browser or lock the device.
- Return to the browser - audio does not resume.
- Press the “ctx.resume()” button - BGM resumes.
- Minimize or lock the device again.
- Return once more - the console now logs the
InvalidStateErrornoted above.
Interesting Notes:
- When the
InvalidStateErroroccurs, it appears that manually callingsoundManager.context.suspend()followed bysoundManager.context.resume()causes audio to play again.
If anyone has experienced this or knows a workaround, I’d greatly appreciate your advice!
Thanks in advance.