Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio not working with emscripten #6385

Closed
rokups opened this issue Oct 12, 2022 · 4 comments
Closed

Audio not working with emscripten #6385

rokups opened this issue Oct 12, 2022 · 4 comments
Assignees
Milestone

Comments

@rokups
Copy link
Contributor

rokups commented Oct 12, 2022

Firefox produces following warning and audio fails to play:

An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page.

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

@icculus
Copy link
Collaborator

icculus commented Oct 12, 2022

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.

@icculus icculus closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2022
@rokups
Copy link
Contributor Author

rokups commented Oct 12, 2022

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! 🙏

@slouken
Copy link
Collaborator

slouken commented Oct 12, 2022

Reopened for documentation

@slouken slouken reopened this Oct 12, 2022
@slouken slouken added this to the 2.26.0 milestone Oct 12, 2022
@icculus
Copy link
Collaborator

icculus commented Oct 28, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants