1

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?

Kevin Mahrous
  • 48
  • 1
  • 5
GijsVh
  • 11
  • 1
  • 1
    Check this SO answer: https://stackoverflow.com/questions/49930680/how-to-handle-uncaught-in-promise-domexception-play-failed-because-the-use – Matthew M. May 17 '22 at 14:42

0 Answers0