emscripten-core / emscripten-core/emscripten

[enhancement] built-in click-to-start in index.html?

Open
#20,084 10 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

We get bug reports from time to time in SDL, that audio isn't working in Emscripten, and of course the problem is not in SDL or Emscripten, but always that the user needs to interact with the page before the browser will allow audio to play.

While it's not a perfect fit for everything, a common solution in games is to put up a "click/tap here to start!" thing in front of the canvas, so the user has to interact with the page before the code even hits main(), so no Emscripten-specific magic has to go into the app itself to deal with audio management.

It would be _extremely_ helpful if the default index.html that emcc outputs has this click-to-start built in, perhaps gated behind a setting in Module to enable/disable it.

It can be extremely daunting to hook into index.html and Module, especially to C programmers that aren't really familiar with HTML or Javascript, especially since index.html is something that seems to magically appear as linker output to the untrained eyes, so I think it would be super-helpful if Emscripten offered this.

(Failing that, I would also be happy with a page in the documentation that says "here's a barebones template you could paste into your index.html to add click-to-play support, and maybe extend youself to make it fancier if you're up to it.")

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.