Skip to content

Instantly share code, notes, and snippets.

@neovov
Created February 9, 2017 15:26
Show Gist options
  • Save neovov/ac38c6f62a837e7ddaab1da7252624c4 to your computer and use it in GitHub Desktop.
Save neovov/ac38c6f62a837e7ddaab1da7252624c4 to your computer and use it in GitHub Desktop.
WritableStream
const source = new ReadableStream({…}); // As seen above
const destination = new WritableStream({
start(controller) {
// Return a promise to signal the construction is asynchronous
return new Promise(resolve => {
const source = new MediaSource();
// Mark the WritableStream as ready when the source is open
source.addEventListener('sourceopen', () => {
this.buffer = source.addSourceBuffer('audio/mpeg');
resolve();
});
player.src = URL.createObjectURL(source);
});
},
write(chunk, controller) {
// When receiving a chunk append it to the player's buffer
this.buffer.appendBuffer(chunk);
}
});
source.pipeTo(destination);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment