# Video playback Screen error

**URL:** <https://psychtoolbox.discourse.group/t/video-playback-screen-error/987>\
**Category:** Uncategorized\
**Created:** [January 18, 2013, 2:57pm UTC](https://psychtoolbox.discourse.group/t/video-playback-screen-error/987 "2013-01-18T14:57:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [January 18, 2013, 2:57pm UTC](https://psychtoolbox.discourse.group/t/video-playback-screen-error/987/1 "2013-01-18T14:57:41Z")

</div>

| I am trying to write a script that plays a video in Psychtoolbox. I keep encountering Screen errors along my way and was wondering if anyone could help? Below is the script so far (part of it at least.) The line that is causing me errors is [tex]=Screen('GetMovieImage', w, movie;   
Thanks  
Annie  
  
screenNumber = max(Screen('Screens'));  
HideCursor;  
gray=GrayIndex(screenNumber);  
[w, wRect]=Screen('OpenWindow', screenNumber, [127 127 127]); %127 127 127 colour of mask  
[a, b] = WindowCenter(w);  
priorityLevel = MaxPriority(w);  
Priority(priorityLevel);  
[movie movieduration fps w h count] = Screen('OpenMovie', w, moviename)  
  
  
  
&nbsp;%read in frame by frame  
while ~KbCheck  
&nbsp;&nbsp;&nbsp; % Wait for next movie frame, retrieve texture handle to it  
&nbsp;&nbsp;&nbsp; [tex] = Screen('GetMovieImage', w, movie);  
  
&nbsp;&nbsp;&nbsp; % Valid texture returned? A negative value means end of movie reached:  
&nbsp;&nbsp;&nbsp; if tex\<=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % We're done, break out of loop:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;  
&nbsp;&nbsp;&nbsp; end;  
  
&nbsp;&nbsp;&nbsp; % Draw the new texture immediately to screen:  
&nbsp;&nbsp;&nbsp; Screen('DrawTexture', w, tex);  
  
&nbsp;&nbsp;&nbsp; % Update display:  
&nbsp;&nbsp;&nbsp; Screen('Flip', w);  
  
&nbsp;&nbsp;&nbsp; % Release texture:  
&nbsp;&nbsp;&nbsp; Screen('Close', tex);  
end;  
  
GlobalStart = GetSecs;  
tic  
for j = 1:length(seqEx)  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; Start = GetSecs;  
&nbsp;&nbsp;&nbsp; stimno = seqEx(j);  
&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp; if (stimno \< 2)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('PlayMovie',movie, 1, 1, 0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %timeindex = Screen('GetMovieTimeIndex', movie);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % [tex] = Screen('GetMovieImage', w, movie);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %Screen('DrawTexture', tex, window);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % movie(mov, 1, obj.FrameRate);   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % Screen('Flip', w)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('CloseMovie', movie);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % Update display:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('Flip', w);  
&nbsp;&nbsp;&nbsp; elseif (stimno \> 1 && stimno \< 9)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %Fix cross:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('DrawText', w, '+', a, b,0);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('Flip', w);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %read in voices instead  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = voices{stimno};  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SDur(j) = size(x, 1) / fs;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; % Present the voice  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wavplay(x, fs);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SOnset(j) = GetSecs - GlobalStart;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; step(j) = mstep(seqEx(j));  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %Answer loop  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keyPressed = 0;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ISI = 5 + rand;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while success == 0 && GetSecs - Start \< ISI  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [keyDown, keyTime, keyCode] = KbCheck;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if strcmp(KbName(keyCode), 'z') == 1 % Button 1  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success = 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RT(j) = keyTime - Start;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Answers(j) = 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; elseif strcmp(KbName(keyCode), 'm') == 1 % Button 2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; success = 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RT(j) = keyTime - Start;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Answers(j) = 2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end  
&nbsp;&nbsp;&nbsp; end  
end  
toc  
 |

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [January 18, 2013, 3:56pm UTC](https://psychtoolbox.discourse.group/t/video-playback-screen-error/987/2 "2013-01-18T15:56:38Z")

</div>

Hi Annie,

 

Basic info is missing:

- what OS + matlab version?

- what is the error you get

 

Furthermore:

- did you run UpdatePsychtoolbox() lately?

- did you read the install instructions for GStreamer?

- did you have a look at the movie playback demos? Do they work? if so, base your code on those demos.

 

Best,

Dee  
  

> 

On Fri, Jan 18, 2013 at 10:57 PM, Annie Pye \<[annie\_pye@...](mailto:annie_pye@...)\> wrote:  

> | I am trying to write a script that plays a video in Psychtoolbox. I keep encountering Screen errors along my way and was wondering if anyone could help? Below is the script so far (part of it at least.) The line that is causing me errors is [tex]=Screen('GetMovieImage', w, movie;   
> Thanks  
> Annie  
>   
> screenNumber = max(Screen('Screens'));  
> HideCursor;  
> gray=GrayIndex(screenNumber);  
> [w, wRect]=Screen('OpenWindow', screenNumber, [127 127 127]); %127 127 127 colour of mask  
> [a, b] = WindowCenter(w);  
> priorityLevel = MaxPriority(w);  
> Priority(priorityLevel);  
> [movie movieduration fps w h count] = Screen('OpenMovie', w, moviename)  
>   
>   
>   
> %read in frame by frame  
> while ~KbCheck  
> % Wait for next movie frame, retrieve texture handle to it  
> [tex] = Screen('GetMovieImage', w, movie);  
>   
> % Valid texture returned? A negative value means end of movie reached:  
> if tex\<=0  
> % We're done, break out of loop:  
> break;  
> end;  
>   
> % Draw the new texture immediately to screen:  
> Screen('DrawTexture', w, tex);  
>   
> % Update display:  
> Screen('Flip', w);  
>   
> % Release texture:  
> Screen('Close', tex);  
> end;  
>   
> GlobalStart = GetSecs;  
> tic  
> for j = 1:length(seqEx)  
>   
> Start = GetSecs;  
> stimno = seqEx(j);  
>   
> if (stimno \< 2)  
>   
> Screen('PlayMovie',movie, 1, 1, 0);  
> %timeindex = Screen('GetMovieTimeIndex', movie);  
> % [tex] = Screen('GetMovieImage', w, movie);  
> %Screen('DrawTexture', tex, window);  
> % movie(mov, 1, obj.FrameRate);   
> % Screen('Flip', w)  
> Screen('CloseMovie', movie);  
> % Update display:  
> Screen('Flip', w);  
> elseif (stimno \> 1 && stimno \< 9)  
> %Fix cross:  
> Screen('DrawText', w, '+', a, b,0);  
> Screen('Flip', w);  
>   
> %read in voices instead  
> x = voices{stimno};  
> SDur(j) = size(x, 1) / fs;  
> % Present the voice  
> wavplay(x, fs);  
> SOnset(j) = GetSecs - GlobalStart;  
> step(j) = mstep(seqEx(j));  
>   
> %Answer loop  
> success = 0;  
> keyPressed = 0;  
> ISI = 5 + rand;  
> while success == 0 && GetSecs - Start \< ISI  
> [keyDown, keyTime, keyCode] = KbCheck;  
> if strcmp(KbName(keyCode), 'z') == 1 % Button 1  
> success = 1;  
> RT(j) = keyTime - Start;  
> Answers(j) = 1;  
> elseif strcmp(KbName(keyCode), 'm') == 1 % Button 2  
> success = 1;  
> RT(j) = keyTime - Start;  
> Answers(j) = 2;  
> end  
> end  
> end  
> end  
> toc  
> |
