jspsych / jsPsych

Create behavioral experiments in a browser using JavaScript
http://www.jspsych.org
MIT License
1.05k stars 679 forks source link

html-button-response/html-keyboard-response + no response = hitching #3359

Open anasophiarc opened 4 months ago

anasophiarc commented 4 months ago

Hi, I am having an issue as I want to use an html response to display a video as well as some text without giving the participant an option to respond (ie. I just want them to watch the video). The issue is that not all of the videos that could possibly be displayed in the trial variable are exactly the same length and so when I set the trial_duration parameter to one fixed value certain clips get cut off/ there is a lot of screen hitching. Does anyone have an idea on a way I can improve upon this/reduce the stutters? Thanks

Here is a snippet of the stimulus function plus some of the other parameters I am currently using: return

Permanent Bank: ${score.toFixed(2)}
    <video id= "outcome-video" width="800" height="450" autoplay>
                <source src="${video}" type="video/mp4">
                Your browser does not support the video tag.
            </video>`

}, 
choices: " ", //no choices -> participant just has to watch the outcome unfold 
response_ends_trial: false, 
trial_duration: 2000, //2 seconds to watch the outcome of decision `
Shaobin-Jiang commented 4 months ago

One way of doing it would be to not set trial_duration at all, but to listen to the ended event of the video element yourself and end the trial manually then. Here is my way of doing it:

const impossible_key = 'impossible-key';
let trial = {
    type: jsPsychVideoKeyboardResponse,
    stimulus: ['./video.mp4'],
    choices: [impossible_key],
    on_load: function () {
        document.querySelector('video').addEventListener('ended', function () {
            jsPsych.pluginAPI.keyDown(impossible_key);
            jsPsych.pluginAPI.keyUp(impossible_key);
        });
    }
};

I have not used the jsPsych finishTrial method because that would mean a lot of extra work. Instead, I set the choices to a key that nobody could possible press as the key is non-existent. Then, I just have to manually dispatch the key down and key up events when video reaches its end.