Skip to content

Commit

Permalink
Merge pull request #1115 from becky-gilbert/audio-bug
Browse files Browse the repository at this point in the history
Fixes #648 - bug with audio and progress bar
  • Loading branch information
becky-gilbert committed Oct 20, 2020
2 parents 94d4403 + fc4ce12 commit 790aafd
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jspsych.js
Expand Up @@ -2354,40 +2354,44 @@ jsPsych.pluginAPI = (function() {
function load_audio_file_html5audio(source, count){
count = count || 1;
var audio = new Audio();
audio.addEventListener('canplaythrough', function(){
audio.addEventListener('canplaythrough', function handleCanPlayThrough(){
audio_buffers[source] = audio;
n_loaded++;
loadfn(n_loaded);
if(n_loaded == files.length){
finishfn();
}
audio.removeEventListener('canplaythrough', handleCanPlayThrough);
});
audio.addEventListener('onerror', function(){
audio.addEventListener('error', function handleError(){
if(count < jsPsych.initSettings().max_preload_attempts){
setTimeout(function(){
load_audio_file_html5audio(source, count+1)
}, 200);
} else {
jsPsych.loadFail();
}
audio.removeEventListener('error', handleError);
});
audio.addEventListener('onstalled', function(){
audio.addEventListener('stalled', function handleStalled(){
if(count < jsPsych.initSettings().max_preload_attempts){
setTimeout(function(){
load_audio_file_html5audio(source, count+1)
}, 200);
} else {
jsPsych.loadFail();
}
audio.removeEventListener('stalled', handleStalled);
});
audio.addEventListener('onabort', function(){
audio.addEventListener('abort', function handleAbort(){
if(count < jsPsych.initSettings().max_preload_attempts){
setTimeout(function(){
load_audio_file_html5audio(source, count+1)
}, 200);
} else {
jsPsych.loadFail();
}
audio.removeEventListener('abort', handleAbort);
});
audio.src = source;
}
Expand Down

0 comments on commit 790aafd

Please sign in to comment.