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

215
Views
loading local file in <audio> tag working alternately

I need to load local audio file into <audio> tag.

I did it with the following code.

Let the user choose a file with:

<ion-input type="file" (change)="laodLocalFile($event)">

Prepare it for <audio> tag:

laodLocalFile(event: any)
{    
  file_url = URL.createObjectURL(event.target.files[0]);
  document.getElementById('audio_file').setAttribute("src", file_url);
}

And use it as following:

<audio id="audio_file" type="audio/mpeg" controls></audio>

I tried it with several different mp3 files. It worked several times, but most of the times it didn't work, without any warning or error.

What can be the issue?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to use domeSanitizer and bypassSecurityTrustUrl() this method bypass security and trust the given value to be a safe style URL, i.e. a value that can be used in hyperlinks or src

constructor(private domSanitizer:DomSanitizer) {    }

And in your method: ...

this.mediaSrc = this.domSanitizer.bypassSecurityTrustUrl(file_url);
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!