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

263
Visualizações
How to properly test for an audio end?

I have an audio setup like this


<html>
<head></head>
<body>
  <script>
    var audio1 = new Audio("music1.mp3");
    document.addEventListener('keydown', function(evt) {
      console.log('hm');
      audio1.play();
    });
    audio1.addEventListener("ended", function() {
      console.log('end');
      audio1.currentTime = 0;
    })
  </script>
</body>
</html>

I click a key to start the audio and console.log('hm'); to make sure it started but whenever the audio ends the second eventListener does not get called and I do not get the "end" message or a restart. I prefer to keep the audio in javascript and not a tag because I have already created the game and changing the audio ways changes about 45% of the game.

Am I doing things wrong? If so please tell me the proper way to do it!

about 4 years ago · Juan Pablo Isaza
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