-
-
Save jayshields/21434f808a95d1c597be7ea110bdf3cc to your computer and use it in GitHub Desktop.
Download Audio from AJAX and Play as Blob
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment