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

174
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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