Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

264
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!