phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37k stars 7.08k forks source link

Phaser sounds/music stop playing in the new iOS 17.5.1 after losing/gaining focus in safari #6829

Closed condeagustin closed 1 month ago

condeagustin commented 4 months ago

Version

Description

After upgrading iOS to 17.5.1 (in any iOS device), when losing and then gaining focus of safari, any phaser sound/music that was playing (before losing focus) is off for the rest of the session. Even if you tap on a UI element that is supposed to produce a sound, the sound never comes back unless you reload the whole page. This issue is 100% reproducible only on iOS 17.5.1. In the previous iOS version (e.g. 17.4.1) I tested it and this issue never happened

Example Test Code

The following official phaser web audio sample reproduces the issue 100% https://labs.phaser.io/view.html?src=src%5C%5Caudio%5C%5CWeb%20Audio%5C%5Caudiosprite.js

Additional Information

Steps to reproduce:

  1. In iOS 17.5.1, open safari with this url https://labs.phaser.io/view.html?src=src%5C%5Caudio%5C%5CWeb%20Audio%5C%5Caudiosprite.js
  2. Tap on the "escape" button. This will play a long sound
  3. Lose focus of safari and wait 1 second
  4. Gain focus of safari
  5. The sound is completely gone and any other sound is also gone no matter if you keep tapping the buttons. The only way to make them sound again is by creating a new Web Audio context and set it into phaser sound manager
damy90 commented 3 months ago

I have the same issue on Phaser 3.80.1 and iOS 17.5.1

There is a browser error in the console (no stack trace): Unhandled Promise Rejection: InvalidStateError: Failed to start the audio device

I was able to reproduce the issue on the phaser webaudio demos: https://labs.phaser.io/view-iframe.html?src=src\audio\Web%20Audio\play%20audio%20file.js

Sometimes it starts working ok for no reason while I was debugging. it can still be reproduced by closing the browser completely and reopening it.

The problem is not reproducible on HTML5 audio demos but I have other issues with that fallback on my games, likely because many sounds play at the same time.

zekeatchan commented 3 months ago

Hi @condeagustin @damy90

Thanks for reporting this issue. Initial testing and investigation shows that iOS 17.5.1 has problems with web audio. There have been user reports elsewhere mentioning even Youtube, Spotify, SoundCloud having audio issues after the 17.5.1 update.

Since it is an issue with iOS itself, we can only wait for Apple to release new iOS updates that will hopefully address this sooner than later.

Some other sites to test and see if the issue persists: https://codepen.io/Rumyra/pen/qyMzqN/ https://soundcloud.com/user-272592510/sets/mario-kart-wii-ost https://pixijs.io/sound/examples/ https://threejs.org/examples/#webaudio_visualizer https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_audio_all

photonstorm commented 1 month ago

Have tested this on iOS 17.6.1 and it works again. Whatever it was, Apple fixed it. So am going to close this issue off.