From 7e63103c2b43f66dd50626527e536a06ae08d291 Mon Sep 17 00:00:00 2001 From: Joel Steres Date: Thu, 30 Jun 2016 03:05:09 -0700 Subject: [PATCH 1/3] Update inProgressCount prior to onError callback in loadBuffer --- lib/webaudiox.loadbuffer.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/webaudiox.loadbuffer.js b/lib/webaudiox.loadbuffer.js index 3012c96..c53fbf6 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 @@ -25,14 +25,14 @@ WebAudiox.loadBuffer = function(context, url, onLoad, onError){ // counter inProgress request WebAudiox.loadBuffer.inProgressCount-- // notify the callback - onLoad(buffer) + onLoad(buffer) // notify WebAudiox.loadBuffer.onLoad(context, url, buffer) }, function(){ - // notify the callback - onError() // counter inProgress request WebAudiox.loadBuffer.inProgressCount-- + // notify the callback + onError() }) } request.send() From ca52cfea8e5055bf2cb1bd30c4bbcf6c3b574d93 Mon Sep 17 00:00:00 2001 From: Joel Steres Date: Thu, 30 Jun 2016 06:49:11 -0700 Subject: [PATCH 2/3] Check for http status code errors or FileReader errors in loadBuffer --- lib/webaudiox.loadbuffer.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/webaudiox.loadbuffer.js b/lib/webaudiox.loadbuffer.js index c53fbf6..7f3b766 100644 --- a/lib/webaudiox.loadbuffer.js +++ b/lib/webaudiox.loadbuffer.js @@ -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){ - // counter inProgress request - WebAudiox.loadBuffer.inProgressCount-- - // notify the callback - onLoad(buffer) - // notify - WebAudiox.loadBuffer.onLoad(context, url, buffer) - }, function(){ + // Check XMLHttpRequest.status or FileReader.error parameter + if( (request.status && 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 onError() - }) + } } request.send() } From 2cf2738ab79929b847f67957d5f066332ba5a102 Mon Sep 17 00:00:00 2001 From: Joel Steres Date: Thu, 30 Jun 2016 09:11:26 -0700 Subject: [PATCH 3/3] Remove extraneous condition from error check. Refresh build. --- build/webaudiox.js | 28 ++++++++++++++++++---------- lib/webaudiox.loadbuffer.js | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) 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 7f3b766..32d678d 100644 --- a/lib/webaudiox.loadbuffer.js +++ b/lib/webaudiox.loadbuffer.js @@ -22,7 +22,7 @@ WebAudiox.loadBuffer = function(context, url, onLoad, onError){ WebAudiox.loadBuffer.inProgressCount++ request.onload = function(){ // Check XMLHttpRequest.status or FileReader.error parameter - if( (request.status && request.status < 400) || (!request.status && !request.error) ){ + if( request.status < 400 || (!request.status && !request.error) ){ context.decodeAudioData(request.response, function(buffer){ // counter inProgress request WebAudiox.loadBuffer.inProgressCount--