Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda