UNPKG

visual-js

Version:

[3.0.26] Prepare for npm usage. Special integration for matrix engine 1.9.0 Thunder.

48 lines (41 loc) 1.48 kB
/** * Important : * Webcam NUI control is under : Created by Romuald Quantin. http://creativecommons.org/licenses/by-nc-sa/3.0/ * If you wanna use this code must be published work with same licence */ function BufferLoader(context, urlList, callback) { this.context = context; this.urlList = urlList; this.onload = callback; this.bufferList = new Array(); this.loadCount = 0; } BufferLoader.prototype.loadBuffer = function (url, index) { // Load buffer asynchronously var request = new XMLHttpRequest(); request.open("GET", url, true); request.responseType = "arraybuffer"; var loader = this; request.onload = function () { // Asynchronously decode the audio file data in request.response loader.context.decodeAudioData( request.response, function (buffer) { if (!buffer) { alert("error decoding file data: " + url); return; } loader.bufferList[index] = buffer; if (++loader.loadCount == loader.urlList.length) loader.onload(loader.bufferList); }); }; request.onerror = function () { alert("BufferLoader: XHR error"); }; request.send(); }; BufferLoader.prototype.load = function () { for (var i = 0; i < this.urlList.length; ++i) this.loadBuffer(this.urlList[i], i); };