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

175
Views
How to fix an uncaught promise from audio?

basically I have this javascript that presents multiple audio as shown below.

var audio = [];

audio["blue"] = new Audio("piano-blue.wav.mp3");
audio["red"] = new Audio("piano-red.wav.mp3");

I use the audio to be heard when a specific image is clicked

         document.querySelector(".red-wheel").addEventListener("click", () => {
            document.querySelector(".red-wheel").innerHTML = "<img src='red-light.svg.svg'>";
            setTimeout(setWheels, 500);
            console.log("red");
            playColor("red");
            
          });

          document.querySelector(".blue-wheel").addEventListener("click", () => {
              document.querySelector(".blue-wheel").innerHTML = "<img src='blue-light.svg.svg'>";
              setTimeout(setWheels, 500);
              console.log("blue");
              playColor("blue");
              
          });

The playColour() function is presented below

 function playColor(color) {
            audio[color].load();
            audio[color].play();
        }

When checking the result the sound is heard which is great but the error is found - Uncaught (in promise) DOMException: The play() request was interrupted by a new load request.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Remove audio[color].load();, it's only useful to load the audio beforehand (which you are not doing, since you're calling it at the same time as .play();, or if you changed the audio URL (which you also seem to not be doing))

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