Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartmemo committed Oct 4, 2012
0 parents commit fe313f8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions abbey-load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* abbeyload.js
* A music asset loader by Stuart Memo
*/

(function (window, undefined) {
var filesLoaded = 0,
numberOfFiles = 0,
context = new webkitAudioContext(),
buffers = [];

var AbbeyLoad = function (files, callback) {
this.files = files || {};
filesLoaded = 0;
numberOfFiles = 0;
loadFiles(this.files, callback);
};

var loadFile = function (fileKey, file, returnObj, callback) {
var request = new XMLHttpRequest();

request.open('GET', file[fileKey], true);
request.responseType = 'arraybuffer';

request.onload = function () {
filesLoaded++;
context.decodeAudioData(request.response, function (decodedBuffer) {
returnObj[fileKey] = decodedBuffer;

if (filesLoaded === numberOfFiles) {
callback(returnObj);
}
});
};

request.send();
};

var loadFiles = function (files, callback) {
var returnObj = {};

files.forEach(function (file, index) {
for (var key in file) {
if (file.hasOwnProperty(key)) {
numberOfFiles++;
loadFile(key, file, returnObj, callback);
}
}

});
};

window.AbbeyLoad = AbbeyLoad;
})(window);

0 comments on commit fe313f8

Please sign in to comment.