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

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

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 Denunciar

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