Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

317
Visualizações
DOMException: play() failed because the user didn't interact with the document first

I keep getting this error that says "DOMException: play() failed because the user didn't interact with the document first." but, I don't know what to do. Any suggestions?

<script>
var audioElement = new Audio();
audioElement.setTrack("assets/music/bensound-acousticbreeze.mp3");
audioElement.audio.play();

</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Hi I'm completely new here, but I seem to have found the answer to this.

That error means that in newest version of Chrome sounds are not allowed to play until the user interacts with the webpage.

So all I did (having had the same issue and stumbling upon your question)

I simply attached the sound to a click (as its my intended design anyway), but if you want to play some music as intro you might need to introduce like a "start" button before that menu or otherwise a check that plays the sound when user interacts with the website.

Sorry that I'm not super technical about this, I am learning also and I hope this helps.

https://gamedev.stackexchange.com/questions/163365/html5-games-play-failed-because-the-user-didnt-interact-with-the-document-fi

If it helps here's a video of how I solved my problem:

https://recordit.co/iMmQ0BCbyN

In the video the sound finally plays when I click but would throw an error when I try to play it on load...

Cheers

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda