fix trial_ends_after_video when video stop time is set - fixes #1533

This commit is contained in:
Becky Gilbert 2021-06-22 13:46:06 -07:00
parent ae332b3347
commit 7b16a1d39a
3 changed files with 15 additions and 0 deletions

View File

@ -229,11 +229,16 @@ jsPsych.plugins["video-button-response"] = (function() {
} }
} }
var stopped = false;
if(trial.stop !== null){ if(trial.stop !== null){
video_element.addEventListener('timeupdate', function(e){ video_element.addEventListener('timeupdate', function(e){
var currenttime = video_element.currentTime; var currenttime = video_element.currentTime;
if(currenttime >= trial.stop){ if(currenttime >= trial.stop){
video_element.pause(); video_element.pause();
if (trial.trial_ends_after_video && !(stopped)) {
stopped = true; // this is to prevent end_trial from being called twice, because the timeupdate event can fire in quick succession
end_trial();
}
} }
}) })
} }

View File

@ -196,11 +196,16 @@ jsPsych.plugins["video-keyboard-response"] = (function() {
} }
} }
var stopped = false;
if(trial.stop !== null){ if(trial.stop !== null){
video_element.addEventListener('timeupdate', function(e){ video_element.addEventListener('timeupdate', function(e){
var currenttime = video_element.currentTime; var currenttime = video_element.currentTime;
if(currenttime >= trial.stop){ if(currenttime >= trial.stop){
video_element.pause(); video_element.pause();
if (trial.trial_ends_after_video && !(stopped)) {
stopped = true; // this is to prevent end_trial from being called twice, because the timeupdate event can fire in quick succession
end_trial();
}
} }
}) })
} }

View File

@ -267,11 +267,16 @@ jsPsych.plugins["video-slider-response"] = (function() {
} }
} }
var stopped = false;
if(trial.stop !== null){ if(trial.stop !== null){
video_element.addEventListener('timeupdate', function(e){ video_element.addEventListener('timeupdate', function(e){
var currenttime = video_element.currentTime; var currenttime = video_element.currentTime;
if(currenttime >= trial.stop){ if(currenttime >= trial.stop){
video_element.pause(); video_element.pause();
if (trial.trial_ends_after_video && !(stopped)) {
stopped = true; // this is to prevent end_trial from being called twice, because the timeupdate event can fire in quick succession
end_trial();
}
} }
}) })
} }