Created
December 21, 2015 22:16
-
-
Save jakelodwick/ee22d8a19e53ed9d65ed to your computer and use it in GitHub Desktop.
load multiple files via XHR, then run a callback
This file contains 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
loadSamples: (urls, callback) -> | |
loaded = [] | |
requests = [] | |
decode = (_raw) => | |
@audio.decodeAudioData _raw, (sample) -> | |
loaded.push sample | |
callback(loaded) if loaded.length is urls.length | |
for url, i in urls | |
requests[i] = new XMLHttpRequest() | |
requests[i].open 'GET', url, true | |
requests[i].responseType = 'arraybuffer' | |
requests[i].onload = -> | |
decode this.response | |
requests[i].send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And if you want to keep track of them (by using an object instead of an array),