Open majaha opened 1 month ago
Teleconf 2024-06-11: let's rephrase the note. The intent here is that start(...)
can be used to start an AudioContext
that was otherwise prevented to start.
Thanks for looking into it.
I'm still having trouble understanding though. Could you give an example of how an AudioContext
can be prevented from starting, but could still be started by AudioScheduledSourceNode.start()
?
If the implementation decides that (e.g.) a click, touch or key press flips the allowed to start
check, then it checks out. From within the handler, you can call .start(...)
, and the AudioContext
resumes. Otherwise, the only way to resume an AudioContext
that did not start automatically is to explicitly call resume()
from a touch/click/key handler.
This is what is implemented in at least two implementations, here's Firefox's:
https://searchfox.org/mozilla-central/source/dom/media/webaudio/AudioBufferSourceNode.cpp#714 https://searchfox.org/mozilla-central/source/dom/media/webaudio/AudioContext.cpp#212
Ah, I think I get what you mean now. Would the note be more correct if it said:
NOTE: This can allow
start()
to start anAudioContext
that is currently allowed to start, but has previously been prevented from starting.
I amended my PR to say that, if that seems good to you: https://github.com/WebAudio/web-audio-api/pull/2589
In the specification for the AudioScheduledSourceNode start() method, step 5 says this:
But 5.2 seems to directly contradict the NOTE underneath. Maybe I'm missing something, but I don't see how both can be true at once. At the very least, it's confusing.
A similar note appears in the AudioBufferSourceNode start() method steps.
In my testing in Firefox and Chrome, the start() method does not allow you to start an AudioContext without a user interaction, so it's the NOTE that disagrees with implementations. And that's what makes sense for preventing Autoplay, too.
The NOTE seems to have been added in https://github.com/WebAudio/web-audio-api/commit/d3607084e71ea54c2d2735f7c540b7c54990015f, but I can't work out what the intention was.