| OLD | NEW |
| 1 function BufferLoader(context, urlList, callback) { | 1 function BufferLoader(context, urlList, callback) { |
| 2 this.context = context; | 2 this.context = context; |
| 3 this.urlList = urlList; | 3 this.urlList = urlList; |
| 4 this.onload = callback; | 4 this.onload = callback; |
| 5 this.bufferList = new Array(); | 5 this.bufferList = new Array(); |
| 6 this.loadCount = 0; | 6 this.loadCount = 0; |
| 7 } | 7 } |
| 8 | 8 |
| 9 BufferLoader.prototype.loadBuffer = function(url, index) { | 9 BufferLoader.prototype.loadBuffer = |
| 10 // Load buffer asynchronously | 10 function(url, index) { |
| 11 var request = new XMLHttpRequest(); | 11 // Load buffer asynchronously |
| 12 request.open("GET", url, true); | 12 let request = new XMLHttpRequest(); |
| 13 request.responseType = "arraybuffer"; | 13 request.open('GET', url, true); |
| 14 request.responseType = 'arraybuffer'; |
| 14 | 15 |
| 15 var loader = this; | 16 let loader = this; |
| 16 | 17 |
| 17 request.onload = function() { | 18 request.onload = |
| 18 loader.context.decodeAudioData( | 19 function() { |
| 19 request.response, | 20 loader.context.decodeAudioData( |
| 20 function (decodedAudio) { | 21 request.response, |
| 21 try { | 22 function(decodedAudio) { |
| 22 loader.bufferList[index] = decodedAudio; | 23 try { |
| 23 if (++loader.loadCount == loader.urlList.length) | 24 loader.bufferList[index] = decodedAudio; |
| 24 loader.onload(loader.bufferList); | 25 if (++loader.loadCount == loader.urlList.length) |
| 25 } catch(e) { | 26 loader.onload(loader.bufferList); |
| 26 console.log(e); | 27 } catch (e) { |
| 27 alert('BufferLoader: unable to load buffer ' + index + ", url:
" + loader.urlList[index]); | 28 console.log(e); |
| 28 } | 29 alert( |
| 29 }, | 30 'BufferLoader: unable to load buffer ' + index + |
| 30 function () { | 31 ', url: ' + loader.urlList[index]); |
| 31 alert('error decoding file data: ' + url); | 32 } |
| 32 }); | 33 }, |
| 33 } | 34 function() { |
| 35 alert('error decoding file data: ' + url); |
| 36 }); |
| 37 } |
| 34 | 38 |
| 35 request.onerror = function() { | 39 request.onerror = |
| 36 alert('BufferLoader: XHR error'); | 40 function() { |
| 37 } | 41 alert('BufferLoader: XHR error'); |
| 42 } |
| 38 | 43 |
| 39 request.send(); | 44 request.send(); |
| 40 } | 45 } |
| 41 | 46 |
| 42 BufferLoader.prototype.load = function() { | 47 BufferLoader.prototype.load = function() { |
| 43 for (var i = 0; i < this.urlList.length; ++i) | 48 for (let i = 0; i < this.urlList.length; ++i) |
| 44 this.loadBuffer(this.urlList[i], i); | 49 this.loadBuffer(this.urlList[i], i); |
| 45 } | 50 } |
| OLD | NEW |