# Playing video in Psychtoolbox

**URL:** <https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872>\
**Category:** Uncategorized\
**Created:** [January 10, 2020, 2:54am UTC](https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872 "2020-01-10T02:54:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Von27](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Von27](https://psychtoolbox.discourse.group/u/Von27)\
**Post date:** [January 10, 2020, 2:54am UTC](https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872/1 "2020-01-10T02:54:29Z")

</div>

Hi everyone,

I want to continually play a video whenever the right or left keyboard is being press.

For the first or 2nd loop of the video playing the last few seconds was remove. But as we press the right or left keyboard longer the full video was played.

Have anyone error issues like this?  
Appreciate any suggestions. Thank you! =)

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [January 13, 2020, 4:10am UTC](https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872/2 "2020-01-13T04:10:04Z")

</div>

Hi, from your your message it is unclear what your exact problem is. PTB can load and play looped video files, you set up looping when you first call `Screen('PlayMovie')`. Please be _more_ specific or show a minimal test case. Have you looked through the various demos, like `SimpleMovieDemo.m`?

Best, Ian

---

<div class="post-metadata">

**Author:** ![Von27](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@Von27](https://psychtoolbox.discourse.group/u/Von27)\
**Post date:** [January 13, 2020, 6:49am UTC](https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872/3 "2020-01-13T06:49:18Z")

</div>

For the first loop the last few seconds were always chop off, but after multiple plays the full video is played.

Here is part of my code:  
%% Present TEST TRIAL  
while(1)  
look\_no = 1;  
test\_phrase\_no=1;

```
            if trial.count > n_total_test_trials; 
                Advance_to_test = 0;
                break
            end
            
            if trial.order(trial.count) == 1 % Even numbers represent Left Trials
                trial.type(trial.count) = 39; % keyBoard code for Right arrow
                trial.key = 'RiteArrow';
                to_present_on_screen = Screens(1,:);
                audio_side = 2;
            elseif trial.order(trial.count) == 2 % Odd numbers represent Right Trials
                trial.type(trial.count) = 37; % keyBoard code for Left arrow
                trial.key = 'LeftArrow';
                to_present_on_screen = Screens(3,:);
                audio_side = 1;
            end                
            clear nextframe;
```

---

<div class="post-metadata">

**Author:** ![Ian-Max-Andolina](https://yyz2.discourse-cdn.com/free1/user_avatar/psychtoolbox.discourse.group/ian-max-andolina/32/4_2.png) [@Ian-Max-Andolina](https://psychtoolbox.discourse.group/u/Ian-Max-Andolina)\
**Post date:** [January 15, 2020, 11:37am UTC](https://psychtoolbox.discourse.group/t/playing-video-in-psychtoolbox/2872/4 "2020-01-15T11:37:47Z")

</div>

That code doesn’t really show the actual part that runs or updates the video; you do have a spelling mistake for the key name though: `trial.key = 'RiteArrow';` – should be `RightArrow`

Did you check that `SimpleMovieDemo` works, and you can also pass your movie into `PlayMovieDemo('/path/to/movie.mp4')` to test it plays without cutting off…
