Merge pull request #1115 from becky-gilbert/audio-bug

Fixes #648 - bug with audio and progress bar
This commit is contained in:
Becky Gilbert 2020-10-20 15:49:09 -07:00 committed by GitHub
commit 790aafd8f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2354,15 +2354,16 @@ 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)
@ -2370,8 +2371,9 @@ jsPsych.pluginAPI = (function() {
} 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)
@ -2379,8 +2381,9 @@ jsPsych.pluginAPI = (function() {
} 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)
@ -2388,6 +2391,7 @@ jsPsych.pluginAPI = (function() {
} else {
jsPsych.loadFail();
}
audio.removeEventListener('abort', handleAbort);
});
audio.src = source;
}