So I made a website that was supposed to redirect the person to another website where they were going to be rickrolled. The GIF of Rick worked fine, but for some reason, I just can’t get the audio file to play. Redirecting to the new website works fine and there are no problems with that.
let audioo = document.getElementById("audi");
audi.play();
console.log("audio funksjonen kjører");
<audio id="audi" src="./RickRoll.mp3" autoplay></audio>
I tried to use the autoplay
attribute in the audio tag, but that did not work. The mp3 file is in the same folder as the HTML and CSS files, so I don’t think the program doesn’t see the mp3 file.
2
Answers
In your code, the autoplay attribute in the tag may not work due to these policies. To comply with browser restrictions and ensure that your audio plays, it’s recommended to initiate media playback as a response to a user action such as clicking a button.
First you have a typo mistake ‘audi.play()’ should be ‘audioo.play’
why don’t you try this