2
I want mp3 to be triggered when entering the html page, but it is giving error and does not work.
The code in javascript:
var audio, playbtn;
function initAudioPlayer(){
audio = new Audio();
audio.src = "audio/Loka%20ft%20Anitta.mp3";
audio.loop = true;
audio.play();
}
window.addEventListener("load", initAudioPlayer);
Javascript responds in the console:
Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.
initAudioPlayer @ audioproj.js:9
load (async)
(anonymous) @ audioproj.js:12
Your code ran perfectly here, see if this answer in English helps you: https://stackoverflow.com/questions/49930680/how-to-handle-uncaught-in-promise-domexception-play-failed-because-the-use
– Daniel Mendes