Don't display autoplay warning on construction of AudioContext
Categories
(Core :: Web Audio, defect)
Tracking
()
People
(Reporter: ciwit31509, Unassigned)
Details
Attachments
(1 file)
|
825 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/110.0
Steps to reproduce:
Create AudioContext in a global scope (to use later with a user gesture).
Actual results:
I get the console warning "The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page."
It is not wrong to create AudioContext outside a user gesture, so unless you are attempting to autoplay there is no reason for the warning.
Expected results:
No warning should display
Updated•2 years ago
|
Updated•2 years ago
|
Comment 1•2 years ago
|
||
flyby, would it be possible to provide a test page to try and reproduce this issue on my side? Thanks
Uploaded test page gives the console warning:
"An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page."
There is no attempt made to start the audioContext automatically.
Comment 3•2 years ago
•
|
||
I've loaded the test page in both Chrome and Nightly on Windows 10x64, and following warning message is displayed in Console:
Google Chrome: The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page.
Nightly 115.0a1: An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page.
Setting this as NEW in order to involve the development team and get an opinion on this.
Comment 4•2 years ago
|
||
Per specification, an AudioContext starts automatically, but browsers can (and do) block this from happening except when users have interacted with the page, or users allow auto-play.
There is no way to create an AudioContext that does not start automatically, because it was specified like this in 2011 and we can't change it now because it would break countless websites, so we block them from auto-playing and display a message for authors to help debugging. This can be perceived as annoying, but it's better than the alternatives. Maybe in a few years we'll be able to remove those messages.
Ok, it may not the most important thing. But you normally would not create the AudioContect in the user gesture as you create it one time to use and then reuse, create it anew every time would be unnecessary and perhaps even mess up the timing and so on. So in reality you always get this warning and by that it fills no purpose. Or you have to write code specifically to NOT get the warning which is also not ideal.
My take is, the warning serves no purpose, and could potentially inspire web developers to write worse code to not see it in the console every time you debug. And I vote for you to follow chromium example in this matter where they have decided to warn only when autoplay is attempted (see chrome issue first post comment 11 and 12).
Thank you
MDN:
It's recommended to create one AudioContext and reuse it instead of initializing a new one each time, and it's OK to use a single AudioContext for several different audio sources and pipeline concurrently.
@comment 4: According to the specs (todays date) AudioContext should start in suspended mode, and if "allowed to start" be set to running. So the AudioContext would not not be started atomatically if not allowed.
Comment 7•2 years ago
|
||
Yes, but this is a breaking change. It has changed recently (a small number of years), it used to always start automatically. Because this is a breaking change, we have a warning in the console so that developers understand why this is happening.
Besides, on other browsers than Firefox on some websites, and on Firefox if you have configured it to do so, it will automatically transition to "running" without user action.
Description
•