mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 16:48:12 +00:00
Merge pull request #1115 from becky-gilbert/audio-bug
Fixes #648 - bug with audio and progress bar
This commit is contained in:
commit
790aafd8f3
12
jspsych.js
12
jspsych.js
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user