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

251
Views
How do i read an audio file from file dialog

I am creating a web where you can upload mp3 files through file dialog, but I don't know how to tell the web to play that sound the user uploaded (?

  function importData() 
{
     let input = document.createElement('input');
     input.type = 'file';
     input.onchange = e => {
    // you can use this method to get file and perform respective operations
     var file = e.target.files[0];
     console.log(file.name);
   }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Once you have the filename from the user you need to get its content which you can do using a FileReader. Once you have the content this can be put as the src of an HTML5 audio element and played.

Here's a simple example:

function getAudio() {
  const input = document.querySelector('input');
  const audio = document.querySelector('audio');
  input.type = 'file';
  input.onchange = e => {
    var file = e.target.files[0];

    var reader = new FileReader();
    reader.addEventListener('load', function(e) {
      audio.src = e.target.result;
      audio.play();
    });
    reader.readAsDataURL(file);
  }
}
getAudio();
<input>
<audio src=""></audio>

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!