Reputation: 609
So I've this warning on my console. I read the documentation : https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
I did everything as they said but I still have this warning. Here's my code :
let context;
window.onload = function() {
context = new AudioContext();
...
}
// click event
document.addEventListener('click', function (e) {
if (e.target.closest('.play1')) {
context.resume().then(() => {
source.start(0);
});
}
})
The warning text is about this line : context = new AudioContext();
Does anyone see what I'm missing ? Thank you very much
Upvotes: 15
Views: 33795
Reputation: 6048
Yes, the warning is because you did not create the context in a user gesture. I find the warning quite annoying because it is not wrong to create the context without a user gesture. What is not allowed is starting/resuming the context without a user gesture.
Since you resume the context with a user click, everything is fine.
I would ignore it. Or create the context with a click or other user gesture.
I wish Chrome would fix the warning so that it only shows up when you try to resume a context without a user gesture.
Upvotes: 21