flutter_soloud
flutter_soloud copied to clipboard
fix: Web, soloud will eventually stop working in iOS Safari
Description
I eventually able to repro this in all mines and my friends iOS devices. Though I haven't found a fast and stable way to repro.
Steps To Reproduce
- An iOS device, not in silent ring (vibration) mode. (It's more complicated in silent ring mode)
- Use built-in Safari, go to https://victorious-dune-08f691f1e.6.azurestaticapps.net/ source code FYI. https://github.com/yangyuan/flutter-issues/blob/soloud/lib/main.dart. The app was built with
flutter build web --pwa-strategy=none --release, I use--pwa-strategy=noneto get rid of cache only. - Click "Play sound", it shall be working first time you load the page.
- Randomly play around, lock screen, leave it idle, or exit/kill/reopen Safari, or go for a coffee. At one point the "Play Sound" will not work anymore, this usually take < 10 mins to happen.
- Once above happens, then there is a stable way to repro: 5.1 Refresh the page, click "Play sound", it shall be working. 5.2 Lock screen or exit Safari, then come back to the page. 5.3 click "Play sound", it shall not make any sound. Click "Reload AudioSource" 5.4 click "Reset Soloud", then click "Play sound", it's back to working.
Expected Behavior
Soloud should always be able to make sound.
Screenshots
N/A
Additional Context
I am working on a game which is targeting mobile browsers. I also encountered similar issue with AudioPlayer. But unlike soloud, I didn't find a way to recover AudioPlayer. AudioPlayer seems also not interested in looking into Web issues.
My two-cent analysis
- "Reload AudioSource" did not work, only re-initialize soloud works. So, my biggest suspicion is around device management. Maybe lock and unlock the screen or quitting the browser trigged something, (for example. a device change?)
- My second suspicion is around service worker. I'm very new to this. Maybe the service worker died for some reason? Maybe iOS browsers manage service worker in a different way? All tested devices were working all fine in the beginning and then, at some point, can stably repro this. Could this because there was something getting added up and eventually trigged some limit?
- I still need find a stable way to repro, but sometimes soloud in one website trigged the sound from another website which failed to play earlier (I was testing soloud in different websites, these websites do not share anything, different domain different asset, and somehow, they can interfere each other?!). This further let me believe there is some issue about device or service worker.
- Its more compilated when silent ring mode is on. The tested page may or may not make sound in the beginning. But on all of the tested devices, soloud eventually make no sounds when silent ring mode is on. Even reset soloud won't help. This is just for your information; silent mode making no sound is still acceptable.
- Physical devices seem also have different but in-a-way also very similar issue https://github.com/alnitak/flutter_soloud/issues/126