1 function BufferLoader(context
, urlList
, callback
) {
2 this.context
= context
;
3 this.urlList
= urlList
;
4 this.onload
= callback
;
5 this.bufferList
= new Array();
9 BufferLoader
.prototype.loadBuffer = function(url
, index
) {
10 // Load buffer asynchronously
11 var request
= new XMLHttpRequest();
12 request
.open("GET", url
, true);
13 request
.responseType
= "arraybuffer";
17 request
.onload = function() {
18 loader
.context
.decodeAudioData(
20 function (decodedAudio
) {
22 loader
.bufferList
[index
] = decodedAudio
;
23 if (++loader
.loadCount
== loader
.urlList
.length
)
24 loader
.onload(loader
.bufferList
);
26 alert('BufferLoader: unable to load buffer' + index
);
30 alert('error decoding file data: ' + url
);
34 request
.onerror = function() {
35 alert('BufferLoader: XHR error');
41 BufferLoader
.prototype.load = function() {
42 for (var i
= 0; i
< this.urlList
.length
; ++i
)
43 this.loadBuffer(this.urlList
[i
], i
);