Skip to content

Instantly share code, notes, and snippets.

@praveenpuglia
Created April 17, 2019 08:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save praveenpuglia/61a296064815f19f391f2c84f12f134b to your computer and use it in GitHub Desktop.
Save praveenpuglia/61a296064815f19f391f2c84f12f134b to your computer and use it in GitHub Desktop.
Download Audio from AJAX and Play as Blob
var a = fetch("http://path/to/audio.wav")
.then(res => {
var reader = res.body.getReader();
return reader.read().then(result => {
return result;
});
})
.then(data => {
console.log(data);
var blob = new Blob([data.value], { type: "audio/wav" });
var blobUrl = URL.createObjectURL(blob);
window.audio = new Audio();
window.audio.src = blobUrl;
window.audio.controls = true;
document.body.appendChild(window.audio);
});
@yairMoshkovitz
Copy link

thanks!
i have a problom, this function load only few secondes.
can you halp my?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment