Hi,
we are investigating about a problem with Chrome: it looks like, starting from April 2018, a new policy for inhibiting autoplay of multimedia content has been introduced. The consequence is that in certain conditions audio is disabled, maybe because of unusual URL detection.
I knew Chrome was going to block autoplay for clips, but not for applications…
Eh, I see HTML5AudioContex in Lime and WebAudioContext in Howler… @singmajesty ?
We need to resume the audio context consequently to an interaction, but… what kind of interaction (a mouse event?), and… where can I find that context to resume?
I have copied the howler.min.js file from Lime 6.3.0 lib/dependencies folder to the same folder of Lime 6.2.0.
I can’t use Openfl 8 + Lime 6.3.0 because of a problem with filters.
I noticed a very annoying problem introduced by the new Chrome policy: when my apps start I play certain sounds (like music) by default, and before the new Chrome everything was ok.
Now sounds don’t start until I interact in some way, and when I do they starts, but the sounds with a loop can’t be stopped anymore, unless I force them to start AFTER the AudioContext has been resumed by the initial interaction. Could it be that these sound effects are initialized (even if they can’t be heard) in a different AudioContext, and when context is resumed the correct reference to them is lost and can’t be controlled/stopped anymore?
It seems that autoplay without user interaction works depending on the server (it works on my server but not in my client server). So I would like to add a button only in this case so I could keep autoplay on my server.
To detect whether browser will require user interaction to play audio, you can check the state of the AudioContext after you’ve created it. If you are allowed to play, it should immediately switch to running . Otherwise it will be suspended . If you listen to the statechange event, you can detect changes asynchronously. Autoplay policy in Chrome | Blog | Chrome for Developers
Is it possible to check the state of the AudioContext so I could know if the sound is blocked?
It’s not a server thing. It’s a chrome version thing.
If chrome (or safari, for that matter) detects that an audio sound begins playing due to an user input then it unlocks the audio.
Browsers tell apart real user inputs from progamatically simulated inputs. We can’t fake it. Said inputs include things like: mouse, keyboard or the order to refresh the webpage.
howler (openfl html5 sound backend) has a protection in place that forces a mute sound to play whenever the user clicks anywhere on the screen thus unlocking the audio.