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

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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