Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions build/webaudiox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down
28 changes: 18 additions & 10 deletions lib/webaudiox.loadbuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down