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

116
Views
Is it possible to put the reader.result in const audio = new Audio("");, namely in ""? If so, please tell me how to do it

Tell me, please, is it possible to put the reader.result in const audio = new Audio("");, namely in ""? If so, please tell me how to do it. Full code:

function previewWAV() {
var preview = document.querySelector('.download-button.fas.fa-download');
var previewDisplay = document.querySelector('.preview-div.wav');
var file    = document.querySelector('#upload').files[0];
var reader  = new FileReader();

previewDisplay.style.display = "block";

reader.onloadend = function () { preview.href = reader.result; const audio = new Audio("reader.result"); }

if (file) { reader.readAsDataURL(file); } else { preview.src = ""; } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

That won't work.

Audio() accepts a URL as its sole parameter.

FileReader.result returns the contents of the file, not its URL.

If the file you're trying to play is already at a URL you can just feed that URL to Audio() and skip the whole FileReader step.

If you're trying to preview a file before upload, you can use URL.createObjectURL() on the file object to generate a usable DOMString you can pass to Audio():

let file = document.querySelector('#upload').files[0];
let fileURL = URL.createObjectURL(file);
let audio = new Audio(fileURL);
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!