diff --git a/build/webaudiox.js b/build/webaudiox.js index 1255e8f..0de9942 100644 --- a/build/webaudiox.js +++ b/build/webaudiox.js @@ -317,7 +317,7 @@ var WebAudiox = WebAudiox || {} /** * Helper to load a buffer - * + * * @param {AudioContext} context the WebAudio API context * @param {String} url the url of the sound to load * @param {Function} onLoad callback to notify when the buffer is loaded and decoded @@ -336,19 +336,27 @@ WebAudiox.loadBuffer = function(context, url, onLoad, onError){ // counter inProgress request WebAudiox.loadBuffer.inProgressCount++ request.onload = function(){ - context.decodeAudioData(request.response, function(buffer){ + // Check XMLHttpRequest.status or FileReader.error parameter + if( request.status < 400 || (!request.status && !request.error) ){ + context.decodeAudioData(request.response, function(buffer){ + // counter inProgress request + WebAudiox.loadBuffer.inProgressCount-- + // notify the callback + onLoad(buffer) + // notify + WebAudiox.loadBuffer.onLoad(context, url, buffer) + }, function(){ + // counter inProgress request + WebAudiox.loadBuffer.inProgressCount-- + // notify the callback + onError() + }) + } else { // counter inProgress request WebAudiox.loadBuffer.inProgressCount-- - // notify the callback - onLoad(buffer) - // notify - WebAudiox.loadBuffer.onLoad(context, url, buffer) - }, function(){ // notify the callback onError() - // counter inProgress request - WebAudiox.loadBuffer.inProgressCount-- - }) + } } request.send() } diff --git a/lib/webaudiox.loadbuffer.js b/lib/webaudiox.loadbuffer.js index 3012c96..32d678d 100644 --- a/lib/webaudiox.loadbuffer.js +++ b/lib/webaudiox.loadbuffer.js @@ -2,7 +2,7 @@ var WebAudiox = WebAudiox || {} /** * Helper to load a buffer - * + * * @param {AudioContext} context the WebAudio API context * @param {String} url the url of the sound to load * @param {Function} onLoad callback to notify when the buffer is loaded and decoded @@ -21,19 +21,27 @@ WebAudiox.loadBuffer = function(context, url, onLoad, onError){ // counter inProgress request WebAudiox.loadBuffer.inProgressCount++ request.onload = function(){ - context.decodeAudioData(request.response, function(buffer){ + // Check XMLHttpRequest.status or FileReader.error parameter + if( request.status < 400 || (!request.status && !request.error) ){ + context.decodeAudioData(request.response, function(buffer){ + // counter inProgress request + WebAudiox.loadBuffer.inProgressCount-- + // notify the callback + onLoad(buffer) + // notify + WebAudiox.loadBuffer.onLoad(context, url, buffer) + }, function(){ + // counter inProgress request + WebAudiox.loadBuffer.inProgressCount-- + // notify the callback + onError() + }) + } else { // counter inProgress request WebAudiox.loadBuffer.inProgressCount-- - // notify the callback - onLoad(buffer) - // notify - WebAudiox.loadBuffer.onLoad(context, url, buffer) - }, function(){ // notify the callback onError() - // counter inProgress request - WebAudiox.loadBuffer.inProgressCount-- - }) + } } request.send() }