Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.47k stars 977 forks source link

Most examples do not work in Safari on Mac #406

Closed crcdng closed 5 years ago

crcdng commented 5 years ago

The following examples played from the website (tone.js r12) do not work, i.e. they fail silently without error message in Safari 12.0.1 on Mac 10.14.1. The examples not listed work.

tambien commented 5 years ago

thanks for the issue, this is probably related to the Autoplay policy on Safari. planning on updating soon as more browsers adopt a similarly strict Autoplay policy.

fabb commented 5 years ago

Since the same Autoplay Policy is now also affective for Chrome, all the same examples are broken for Chrome as well. Please ask authors to fix them, they are awesome!

eltomito commented 5 years ago

Firefox Nightly breaks them too as of today. The autoplay policy also broke my app that I'm developing using Tone.js. Is there a way to fix this in the code, please?

tambien commented 5 years ago

@eltomito the solution is to invoke Tone.context.resume() from an explicit user action. There is little that a library can do to get around the Autoplay policy, it is something that each developer must do for their own application. i will add a note to the top of the README

tambien commented 5 years ago

fixed with the latest release!

eltomito commented 5 years ago

@tambien Yes, this solves it! But there's a catch: Tone.context.resume() has to be the first thing you do with the suspended context. Otherwise, audio is irreversibly disabled for the page. Even just creating a Tone.Synth() when the context is suspended breaks it beyond repair. At least that's how it works in Firefox Nightly.

tambien commented 5 years ago

🙄 oh man, why would they do that?!