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

96
Visualizações
Need help getting Web Audio to play from a Javascript file

I am trying to get an audio file to play from my Javascript file.

I have this line in my HTML File within the Body section:

<audio id="play" src="https://freesound.org..."></audio>

In my JS file I make these calls:

var audio = document.getElementById("play");
audio.play();

Now, when I run my code through the Browser, I get this error:

Unhandled Promise Rejection: NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.

What does this mean? Where can I reference audio that the Web Server allows access?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

From https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play:

NotAllowedError DOMException Provided if the user agent (browser) or operating system doesn't allow playback of media in the current context or situation. This may happen, for example, if the browser requires the user to explicitly start media playback by clicking a "play" button.

Nowadays, fortunately, website are no longer allowed to just start playing audio when you open them. The user first needs to interact with the page in some way. If you use the same code in a click-handler of a button, e.g., it should work.

about 4 years ago · Juan Pablo Isaza Relatório

0

It might be the website refuse your request but there is other way to do it. You can put the music file to your project folder and then type the folder path the music file in to src path in audio tag.

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