Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/buffer-loader.js

Issue 2537183002: Encode HRTF database using FLAC (Closed)
Patch Set: Remove unneeded files. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 = function(url, index) {
10 // Load buffer asynchronously 10 // Load buffer asynchronously
11 var request = new XMLHttpRequest(); 11 var request = new XMLHttpRequest();
12 request.open("GET", url, true); 12 request.open("GET", url, true);
13 request.responseType = "arraybuffer"; 13 request.responseType = "arraybuffer";
14 14
15 var loader = this; 15 var loader = this;
16 16
17 request.onload = function() { 17 request.onload = function() {
18 loader.context.decodeAudioData( 18 loader.context.decodeAudioData(
19 request.response, 19 request.response,
20 function (decodedAudio) { 20 function (decodedAudio) {
21 try { 21 try {
22 loader.bufferList[index] = decodedAudio; 22 loader.bufferList[index] = decodedAudio;
23 if (++loader.loadCount == loader.urlList.length) 23 if (++loader.loadCount == loader.urlList.length)
24 loader.onload(loader.bufferList); 24 loader.onload(loader.bufferList);
25 } catch(e) { 25 } catch(e) {
26 alert('BufferLoader: unable to load buffer' + index); 26 console.log(e);
27 alert('BufferLoader: unable to load buffer ' + index + ", url: " + loader.urlList[index]);
27 } 28 }
28 }, 29 },
29 function () { 30 function () {
30 alert('error decoding file data: ' + url); 31 alert('error decoding file data: ' + url);
31 }); 32 });
32 } 33 }
33 34
34 request.onerror = function() { 35 request.onerror = function() {
35 alert('BufferLoader: XHR error'); 36 alert('BufferLoader: XHR error');
36 } 37 }
37 38
38 request.send(); 39 request.send();
39 } 40 }
40 41
41 BufferLoader.prototype.load = function() { 42 BufferLoader.prototype.load = function() {
42 for (var i = 0; i < this.urlList.length; ++i) 43 for (var i = 0; i < this.urlList.length; ++i)
43 this.loadBuffer(this.urlList[i], i); 44 this.loadBuffer(this.urlList[i], i);
44 } 45 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698