Error Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first, how can i solve this?

Viewed 856

I'm making a game for a school project and want to add music to the login screen. When my page loads, I get the error Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first.

This is my function to play the audio

function speelmuziek() {
 var audio = new Audio('sounds/waitsound.mp3');
 audio.play()
}

And I use this in the body of my page to load the function.

<body onload="speelmuziek()">

How can I solve this?

0 Answers
Related