diff --git a/plugins/jspsych-video-button-response.js b/plugins/jspsych-video-button-response.js index b2179b96..9a1ff164 100644 --- a/plugins/jspsych-video-button-response.js +++ b/plugins/jspsych-video-button-response.js @@ -229,11 +229,16 @@ jsPsych.plugins["video-button-response"] = (function() { } } + var stopped = false; if(trial.stop !== null){ video_element.addEventListener('timeupdate', function(e){ var currenttime = video_element.currentTime; if(currenttime >= trial.stop){ 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(); + } } }) } diff --git a/plugins/jspsych-video-keyboard-response.js b/plugins/jspsych-video-keyboard-response.js index f7896091..a4a9b860 100644 --- a/plugins/jspsych-video-keyboard-response.js +++ b/plugins/jspsych-video-keyboard-response.js @@ -196,11 +196,16 @@ jsPsych.plugins["video-keyboard-response"] = (function() { } } + var stopped = false; if(trial.stop !== null){ video_element.addEventListener('timeupdate', function(e){ var currenttime = video_element.currentTime; if(currenttime >= trial.stop){ 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(); + } } }) } diff --git a/plugins/jspsych-video-slider-response.js b/plugins/jspsych-video-slider-response.js index 6eab4401..7a52cafa 100644 --- a/plugins/jspsych-video-slider-response.js +++ b/plugins/jspsych-video-slider-response.js @@ -267,11 +267,16 @@ jsPsych.plugins["video-slider-response"] = (function() { } } + var stopped = false; if(trial.stop !== null){ video_element.addEventListener('timeupdate', function(e){ var currenttime = video_element.currentTime; if(currenttime >= trial.stop){ 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(); + } } }) }