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

AudioContext fails to start in guess the tempo #3

Open
shamgang opened this issue Jan 30, 2022 · 0 comments · May be fixed by #4
Open

AudioContext fails to start in guess the tempo #3

shamgang opened this issue Jan 30, 2022 · 0 comments · May be fixed by #4

Comments

@shamgang
Copy link

The following warning appears every time for me on the first attempt in the guess the tempo game.
"The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page."
When this warning appears, the audio fails to play and the game hangs.
If I click the "<< Back" link and then choose the game again, it works correctly

The reason for this is that the Timbre.js library starts an AudioContext on load, which happens before a user interaction,
and Chrome now blocks autoplay of audio before a user interaction.
If I let the game crash and go back and select it again, Chrome considers the first attempt a user interaction
so it works the second time.

This should be fixed in the timbre repo by
either delaying the AudioContext start or using resume() later on before playing audio.
However timbre is no longer maintained, so I've prepared a patch fix. Pull request coming soon.

Using Chrome 97.0.4692.99

shamgang added a commit to shamgang/bpm-game that referenced this issue Jan 30, 2022
Fixes tgwizard#3

The timbre library attemps to start an AudioContext on load.
This fails in newer versions of Chrome because autoplay is blocked
until the user has made an interaction.
The best fix is for the timbre library to wait for interaction
or call context.resume() before attempting to play audio.
However, the timbre repo is no longer maintained.
As a patch fix, dynamically load the library after the first
interaction in the guess tempo game (READY is clicked).
The timbre library is removed entirely from the keep bpm game
as it is not used.
@shamgang shamgang linked a pull request Jan 30, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant