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

197
Visualizações
how to preload audio file using javascript?

how to load audio file in a function call without any human interaction. Is this possible only using the javascript? I have tried this code below but it is not working -

const music = new Audio("audiofile.mp3");
function playMusic(){
    music.play();
};
playMusic();
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Check the path for the Audio File.

The audio file must be in the main directory. (The directory in which index.html is present ).

Check here for Working Code.

about 4 years ago · Juan Pablo Isaza Relatório

0

I think you want audio to play automatically without any user actually playing the audio? if so you can do:

 const music = new Audio("audiofile.mp3");
 window.onload = function playMusic(){
 music.play();
  };

this will play the audio as soon as the page is loaded, alternatively you can use event listeners to play the audio when certain events happen on the page.

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