Created
April 26, 2015 10:08
-
-
Save sgentle/58e3e37c28a7662d014f to your computer and use it in GitHub Desktop.
Audio loops in CoffeeScript with fetch and Promises
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
ctx = new (AudioContext || webkitAudioContext) | |
addAudio = (src) -> | |
fetch src | |
.then (response) -> response.arrayBuffer() | |
.then (audioData) -> new Promise (accept) -> ctx.decodeAudioData audioData, accept | |
.then (buffer) -> | |
node = ctx.createBufferSource() | |
node.buffer = buffer | |
node.loop = true | |
node.connect ctx.destination | |
node.start(0) | |
node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment