Reputation: 2505
Though I only play audio in response to clicks, I initialize the AudioContext and buffers and such when the script loads.
In mobile Chrome 57.0.2987.132 the console shows the following warning when loaded from an iframe:
An AudioContext in a cross origin iframe must be created or resumed from a user gesture to enable audio output.
For audio to work I recreate the AudioContext on first click. Is there a way to simply activate the existing AudioContext on the first click? Also can I detect whether the audio is currently blocked?
References:
Upvotes: 1
Views: 1947
Reputation: 13918
The AudioContext.state will tell you if it's "running" or "suspended". If it's "suspended", call AudioContext.resume() from inside a user gesture, and it should start it up for you (without having to recreate state).
Upvotes: 4