I keep getting this message when trying to play audio on my chrome book using Js below:
"DOMException: play() failed because the user didn't interact with the document first."
<script>
window.addEventListener('load', (event) => {
console.log('page is fully loaded');
console.log('playing music');
var audioElement = new Audio('indie.mp3').play();
if (audioElement !== undefined) {
audioElement.then(_ => {
// Autoplay started!
}).catch(error => {
// Autoplay was prevented.
// Show a "Play" button so that user can start playback.
console.log(error);
});
}
});
</script>