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

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

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 Report

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