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

Handle Chrome audio autoplay policy change #110

Open
ericrosenbaum opened this issue Nov 16, 2018 · 5 comments
Open

Handle Chrome audio autoplay policy change #110

ericrosenbaum opened this issue Nov 16, 2018 · 5 comments
Labels
Milestone

Comments

@ericrosenbaum
Copy link
Collaborator

ericrosenbaum commented Nov 16, 2018

We're currently getting this console warning:

The Web Audio autoplay policy will be re-enabled in Chrome 70 (October 2018). Please check that your website is compatible with it.

The documentation here suggests that the change in fact will occur in December.

@ericrosenbaum ericrosenbaum added this to the November 2018 milestone Nov 16, 2018
@ericrosenbaum ericrosenbaum self-assigned this Nov 16, 2018
@ericrosenbaum
Copy link
Collaborator Author

ericrosenbaum commented Nov 16, 2018

Some initial findings:

  • You can start chrome with a flag to enable the new autoplay policy like this:
    /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-features=AutoplayIgnoreWebAudio
  • Scratch's ability to play sound is almost completely unaffected as far as I can tell, because you almost always have clicked on something (such as the green flag or a sprite) before sound needs to play, and at that point it is allowed to play.
  • A keypress by itself (i.e. without any mouse clicks having occurred) seems to be sufficient to allow the sound to play.
  • Mac Safari, as far as I can tell, already implements exactly this same policy (but we didn't notice).
  • There is, unfortunately, one problem: there is a way to play a sound without any user interaction (i.e. not even a green flag click), using the "when timer > 10" hat block. As far as I know this is the only way. In this case, on Chrome with the new autoplay policy (and on Safari currently), if you do not click on anything or press any keys, when you load the project, the sound will not start after the timer crosses 10s. As soon as you click or press a key, the sound will start.

I can think of two ways to proceed:

  • No fix. Sounds started by the when timer block will not play until there has been a user interaction. This matches the intent of the autoplay policy.
  • We have a bug where sounds are not allowed to start if triggered by the when timer block without any user interaction, and we need to handle it somehow. This could be:
    • Detecting this (rare) situation, and showing some kind of notification ("click to enable Scratch to play sound")
    • Some other strategy??

@ericrosenbaum
Copy link
Collaborator Author

Curious about your thoughts on this @paulkaplan

@paulkaplan
Copy link
Contributor

Thanks for the thorough investigation! It is kind of funny because using the when "timer > 0 => play sound" construction is totally the scratch equivalent of autoplaying videos, so it makes sense that it would get blocked.

I'm curious about which scratch2 views actually play audio with no user interaction. The project page has the green flag overlay that starts the VM, so it wouldn't effect the project there, which is probably our main concern. The places that do rely on autoplay right now are:

  1. Going directly to /#editor (will be /editor in 3.0)
  2. Embed with autoplay=true does autoplay right now (not clear if that will exist in 3.0?)

@ericrosenbaum ericrosenbaum modified the milestones: November 2018, Backlog Nov 27, 2018
@ericrosenbaum
Copy link
Collaborator Author

We are going with the "no fix" option for now, but leaving this in the backlog.

We are considering removing the autoplay option from embed mode.

@ericrosenbaum ericrosenbaum removed their assignment Nov 27, 2018
@towerofnix
Copy link
Contributor

towerofnix commented Dec 2, 2018

We are considering removing the autoplay option from embed mode.

For later discussion, I think it would be better to stay away from removing autoplay. It could still be a useful option on sites that, for example, specifically embed the player so that it's "flush" with the rest of the site's design; having to click the no-autoplay overlay green flag could clash with that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants