if the user has autoplay disabled I want javascript to detect it and do something as an alternative. This triggers after certain element is added to the DOM dynamically.
var playit = audio.play();
if(playit !== undefined) {
playit.then(_ => {// Autoplay started!
}).catch(error => {
console.log('cant play it');
});
}
but I dont get my custom error on the console, instead an error saying that the user has to interact. How can I fix this?
use async/await syntax:
(
async function test() {
var playit = await audio.play();
}
)();