Closed rokups closed 2 years ago
Yeah, you need to gate your app behind some sort of click to start it, as browsers no longer let you start audio before the user has manually interacted with it.
Like the "click or tap to begin" screen here:
https://icculus.org/~icculus/emscripten/flappy-audio/
We could delay audio init, but it makes things more complex, risks devices failing later when we report them as successfully opened, won't help you if you have a passive media player the user doesn't interact with and it's only a matter of time before browsers move other features behind this same requirement anyhow.
The code in that example that handles this is here, in the startClickToPlay
function:
https://icculus.org/~icculus/emscripten/flappy-audio/dragonruby-html5-loader.js
It puts up a temporary UI to wait for a click, deletes that UI, then hands off to an Emscripten app that uses SDL2.
Feel free to steal that code.
I suspected as much... Is this documented anywhere? I bet i wont be last one wondering how to approach this.
Thanks for code to steal too! :pray:
Reopened for documentation
Added a note, but this makes me want to write more comprehensive documentation for the platform, which I will do sometime after 2.26.0 ships, I hope.
Firefox produces following warning and audio fails to play:
A bit of search indicates that this is a new browser restriction, which prevents AudioContext from being initialized outside of user event callbacks.
Firefox v105.0.2 SDL v2.24.0