In my Flutter Web App, I have a sound that plays after a timer expires. It's a stop watch utility. In my Apple and Android apps, on desktop browsers...it works fine everywhere except on iOS Chrome and Safari. Sound is locked down on those applications to only play on a user tap....this is by design for iphones and tablets by Apple.
In order to start the times, the user taps, it's just that 4-7 seconds later. My requirement is for the timer to expire and a sound should play. I installed a mute/unmute, which will play the sound on unmute...so the volume is set and the sound does play on unmute. But when starting the time, it will not play on timer expiration.
I can't imaging there isn't a viable solution out there. Thoughts?
iOS, both with Chrome and Safari don't allow sounds unless initiated by a user action. The delay kills the sound.
You need to start the sound on a user action, then create a listener, and pause as soon as it starts. Then you can resume the sound later. It's asynchronous, so you need the listener.
Future resume() async {
await player.play();
}
Future start() async {
await player.stop();
await player.setUrl('asset:/assets/sounds/sound.wav');
player.play();
player.playerStateStream.listen((state) {
if (state.playing && playStart) {
debugPrint('quick pause here');
playerSafe.pause();
}
});
}