comparison core.js @ 2113:d2abe3b139d2

Interfaces report error if audio cannot be loaded/decoded/played
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 22 Feb 2016 15:48:28 +0000
parents 9f24a593dda9
children 943b0ba7ec83
comparison
equal deleted inserted replaced
2112:705025e30784 2113:d2abe3b139d2
980 var bufferObj = this; 980 var bufferObj = this;
981 981
982 // Create callback to decode the data asynchronously 982 // Create callback to decode the data asynchronously
983 this.xmlRequest.onloadend = function() { 983 this.xmlRequest.onloadend = function() {
984 // Use inbuilt WAVE decoder first 984 // Use inbuilt WAVE decoder first
985 if (this.status == -1) {return;}
985 var waveObj = new WAVE(); 986 var waveObj = new WAVE();
986 if (waveObj.open(bufferObj.xmlRequest.response) == 0) 987 if (waveObj.open(bufferObj.xmlRequest.response) == 0)
987 { 988 {
988 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate); 989 bufferObj.buffer = audioContext.createBuffer(waveObj.num_channels,waveObj.num_samples,waveObj.sample_rate);
989 for (var c=0; c<waveObj.num_channels; c++) 990 for (var c=0; c<waveObj.num_channels; c++)
1009 { 1010 {
1010 console.log('FATAL - Fragment '+audioObj.id+' 404 error'); 1011 console.log('FATAL - Fragment '+audioObj.id+' 404 error');
1011 console.log('URL: '+audioObj.url); 1012 console.log('URL: '+audioObj.url);
1012 errorSessionDump('Fragment '+audioObj.id+' 404 error'); 1013 errorSessionDump('Fragment '+audioObj.id+' 404 error');
1013 } 1014 }
1014 this.status = -1; 1015 this.parent.status = -1;
1015 } 1016 }
1016 }); 1017 });
1017 } 1018 }
1018 if (bufferObj.buffer != undefined) 1019 if (bufferObj.buffer != undefined)
1019 { 1020 {
1020 bufferObj.status = 2; 1021 bufferObj.status = 2;
1021 calculateLoudness(bufferObj,"I"); 1022 calculateLoudness(bufferObj,"I");
1022 } 1023 }
1023 }; 1024 };
1025
1026 // Create callback for any error in loading
1027 this.xmlRequest.onerror = function() {
1028 this.parent.status = -1;
1029 for (var i=0; i<this.parent.users.length; i++)
1030 {
1031 this.parent.users[i].state = -1;
1032 if (this.parent.users[i].interfaceDOM != null)
1033 {
1034 this.parent.users[i].bufferLoaded(this);
1035 }
1036 }
1037 }
1038
1024 this.progress = 0; 1039 this.progress = 0;
1025 this.progressCallback = function(event){ 1040 this.progressCallback = function(event){
1026 if (event.lengthComputable) 1041 if (event.lengthComputable)
1027 { 1042 {
1028 this.parent.progress = event.loaded / event.total; 1043 this.parent.progress = event.loaded / event.total;
1050 for (var objects of this.users) 1065 for (var objects of this.users)
1051 { 1066 {
1052 if (audioObject.id == objects.id){return 0;} 1067 if (audioObject.id == objects.id){return 0;}
1053 } 1068 }
1054 this.users.push(audioObject); 1069 this.users.push(audioObject);
1055 if (this.status == 3) 1070 if (this.status == 3 || this.status == -1)
1056 { 1071 {
1057 // The buffer is already ready, trigger bufferLoaded 1072 // The buffer is already ready, trigger bufferLoaded
1058 audioObject.bufferLoaded(this); 1073 audioObject.bufferLoaded(this);
1059 } 1074 }
1060 } 1075 }
1265 1280
1266 this.bufferLoaded = function(callee) 1281 this.bufferLoaded = function(callee)
1267 { 1282 {
1268 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the 1283 // Called by the associated buffer when it has finished loading, will then 'bind' the buffer to the
1269 // audioObject and trigger the interfaceDOM.enable() function for user feedback 1284 // audioObject and trigger the interfaceDOM.enable() function for user feedback
1285 if (callee.status == -1) {
1286 // ERROR
1287 this.state = -1;
1288 if (this.interfaceDOM != null) {this.interfaceDOM.error();}
1289 this.buffer = callee;
1290 return;
1291 }
1270 if (audioEngineContext.loopPlayback){ 1292 if (audioEngineContext.loopPlayback){
1271 // First copy the buffer into this.buffer 1293 // First copy the buffer into this.buffer
1272 this.buffer = new audioEngineContext.bufferObj(); 1294 this.buffer = new audioEngineContext.bufferObj();
1273 this.buffer.url = callee.url; 1295 this.buffer.url = callee.url;
1274 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate); 1296 this.buffer.buffer = audioContext.createBuffer(callee.buffer.numberOfChannels, callee.buffer.length, callee.buffer.sampleRate);
1306 this.interfaceDOM = interfaceObject; 1328 this.interfaceDOM = interfaceObject;
1307 this.metric.initialise(interfaceObject.getValue()); 1329 this.metric.initialise(interfaceObject.getValue());
1308 if (this.state == 1) 1330 if (this.state == 1)
1309 { 1331 {
1310 this.interfaceDOM.enable(); 1332 this.interfaceDOM.enable();
1311 } 1333 } else if (this.state == -1) {
1334 // ERROR
1335 this.interfaceDOM.error();
1336 return;
1337 }
1312 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId()); 1338 this.storeDOM.setAttribute('presentedId',interfaceObject.getPresentedId());
1313 }; 1339 };
1314 1340
1315 this.loopStart = function(setTime) { 1341 this.loopStart = function(setTime) {
1316 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime); 1342 this.outputGain.gain.linearRampToValueAtTime(this.onplayGain,setTime);