Created
February 9, 2017 15:26
-
-
Save neovov/ac38c6f62a837e7ddaab1da7252624c4 to your computer and use it in GitHub Desktop.
WritableStream
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
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