Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!