From 7b16a1d39ab38b3a01c33c9d0a2fec06524e81ee Mon Sep 17 00:00:00 2001 From: Becky Gilbert Date: Tue, 22 Jun 2021 13:46:06 -0700 Subject: [PATCH] fix trial_ends_after_video when video stop time is set - fixes #1533 --- plugins/jspsych-video-button-response.js | 5 +++++ plugins/jspsych-video-keyboard-response.js | 5 +++++ plugins/jspsych-video-slider-response.js | 5 +++++ 3 files changed, 15 insertions(+) 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(); + } } }) }