phetsims / vibe

Library for handling audio for PhET simulations. Provides cross-platform support and enables usage of base64 audio embedded in an HTML document.
MIT License
3 stars 3 forks source link

Autoplay WebAudio cannot start #32

Closed phet-steele closed 5 years ago

phet-steele commented 6 years ago

When I load https://bayes.colorado.edu/dev/html/area-model-algebra/1.0.0-rc.1/phet/area-model-algebra_all_phet.html in Chrome, I get the following warning:

The AudioContext was not allowed to start. It must be resume (or created) after a user gesture on the page. https://goo.gl/7K7WLu

The link: https://goo.gl/7K7WLu If I see this warning, the audio in that sim does not work. If I don't see this warning, all is well.

I've only seen this on one Win 10 computer (out of three Win 10 Chromes and one macOS 10.13.4 Chrome), and I only see this on first load. Therefore, it is advised to open the sim in incognito while testing.

This was found while testing phetsims/QA/issues/113. @ariel-phet @jbphet please advise on how to proceed.

jonathanolson commented 6 years ago

70 went live, and I can confirm this looks bumped to 71:

The Web Audio autoplay policy will be re-enabled in Chrome 71 (December 2018). Please check that your website is compatible with it. https://goo.gl/7K7WLu
KatieWoe commented 5 years ago

71 has implemented this. When doing an RC with a game I did not encounter any issues with normal use. If you run a fuzz test the sound will not play as it is not a user input.

jbphet commented 5 years ago

As @KatieWoe noted, this restriction of the audio context is now live in Chrome as of version 71. I tested several sims, including those with and without our explicit code to handle an initially suspended audio context, and they all still generate sound. From this testing, it would appear that the policy is implemented such that the audio context is resumed automatically by the browser as soon as the user interacts with the web page. This seem to me like a good way to approach it, since their original attempt required explicit handling of this situation and ended up breaking the sound on a lot of HTML5 games and apps.

I think our work here is done. I'm going to leave the workaround in place, and will likely reference this issue if we ever need to see the history of it, especially how it relates to our sims, but I don't think that there is anything more that needs doing. Closing.