# stopping movie playback

**URL:** <https://psychtoolbox.discourse.group/t/stopping-movie-playback/1896>\
**Category:** Uncategorized\
**Created:** [October 23, 2007, 9:50pm UTC](https://psychtoolbox.discourse.group/t/stopping-movie-playback/1896 "2007-10-23T21:50:30Z")\
**Posts on this page:** 3\
**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:** [October 23, 2007, 9:50pm UTC](https://psychtoolbox.discourse.group/t/stopping-movie-playback/1896/1 "2007-10-23T21:50:30Z")

</div>

Hi all, I am having trouble with stopping movie playback using  
Screen(PlayMovie). Here is the script I am using:  
  
  
for i=1:ntrials;  
  
film=strcat('/Users/jeph/Documents/Psychtoolbox\_experiments/scam/movies/',char(moviename(i)));  
  
 [movie] = Screen('OpenMovie', win, film);  
  
 Screen('PlayMovie', movie, 1, 0, 1.0);  
  
 movietexture=0;   
  
 while(movietexture\>=0)  
  
 [movietexture] = Screen('GetMovieImage', win, movie, 0);  
  
 if (movietexture\>0)  
 Screen('DrawTexture', win, movietexture);  
 Screen('Flip', win);  
 Screen('Close', movietexture);  
 movietexture=0;  
 end;  
  
 [keyIsDown, secs, keyCode]=KbCheck;  
 if (keyIsDown==1)  
 if keyCode(KbName('ESCAPE'))  
 droppedframes=Screen('PlayMovie', movie, 0, 0, 0);  
 Screen('CloseMovie', movie);  
 break;  
 end;  
 end;  
 end;  
  
 Screen('PlayMovie', movie, 0, 0, 0);  
 Screen('CloseMovie', movie);  
end  
  
  
Whenever I press ESC to stop playback, it gives the error message that  
the movie handle does not exist. It does not have any problem when the  
same code is used after the display while loop (no error then). Any ideas?  
  
Thanks in advance,  
  
 - Jeff

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [October 24, 2007, 4:09pm UTC](https://psychtoolbox.discourse.group/t/stopping-movie-playback/1896/2 "2007-10-24T16:09:51Z")

</div>

Simple: You close the movie in your if(kbName('EsCAPe...  
statement, then break out of the while loop, then try  
to stop/close the movie agan that's been closed already,  
so its handle is invalid --\> error.  
  
-mario  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "lejeph" \<jloucks@...\> wrote:  
> \>  
> \> Hi all, I am having trouble with stopping movie playback using  
> \> Screen(PlayMovie). Here is the script I am using:  
> \>   
> \>   
> \> for i=1:ntrials;  
> \>   
> \> film=strcat('/Users/jeph/Documents/Psychtoolbox\_experiments/scam/movies/',char  
> (moviename(i)));  
> \>   
> \> [movie] = Screen('OpenMovie', win, film);  
> \>   
> \> Screen('PlayMovie', movie, 1, 0, 1.0);  
> \>   
> \> movietexture=0;   
> \>   
> \> while(movietexture\>=0)  
> \>   
> \> [movietexture] = Screen('GetMovieImage', win, movie, 0);  
> \>   
> \> if (movietexture\>0)  
> \> Screen('DrawTexture', win, movietexture);  
> \> Screen('Flip', win);  
> \> Screen('Close', movietexture);  
> \> movietexture=0;  
> \> end;  
> \>   
> \> [keyIsDown, secs, keyCode]=KbCheck;  
> \> if (keyIsDown==1)  
> \> if keyCode(KbName('ESCAPE'))  
> \> droppedframes=Screen('PlayMovie', movie, 0, 0, 0);  
> \> Screen('CloseMovie', movie);  
> \> break;  
> \> end;  
> \> end;  
> \> end;  
> \>   
> \> Screen('PlayMovie', movie, 0, 0, 0);  
> \> Screen('CloseMovie', movie);  
> \> end  
> \>   
> \>   
> \> Whenever I press ESC to stop playback, it gives the error message that  
> \> the movie handle does not exist. It does not have any problem when the  
> \> same code is used after the display while loop (no error then). Any ideas?  
> \>   
> \> Thanks in advance,  
> \>   
> \> - Jeff  
> \>

---

<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:** [October 24, 2007, 5:29pm UTC](https://psychtoolbox.discourse.group/t/stopping-movie-playback/1896/3 "2007-10-24T17:29:17Z")

</div>

Ah, thanks Mario! I was worried it would be something embarassingly   
easy like that :)  
  
--- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "Mario Kleiner"   
\<mario.kleiner@...\> wrote:  

> \>  
> \> Simple: You close the movie in your if(kbName('EsCAPe...  
> \> statement, then break out of the while loop, then try  
> \> to stop/close the movie agan that's been closed already,  
> \> so its handle is invalid --\> error.  
> \>   
> \> -mario  
> \>   
> \> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "lejeph" \<jloucks@\> wrote:  
> \> \>  
> \> \> Hi all, I am having trouble with stopping movie playback using  
> \> \> Screen(PlayMovie). Here is the script I am using:  
> \> \>   
> \> \>   
> \> \> for i=1:ntrials;  
> \> \>   
> \> \> film=strcat

('/Users/jeph/Documents/Psychtoolbox\_experiments/scam/movies/',char  

> \> (moviename(i)));  
> \> \>   
> \> \> [movie] = Screen('OpenMovie', win, film);  
> \> \>   
> \> \> Screen('PlayMovie', movie, 1, 0, 1.0);  
> \> \>   
> \> \> movietexture=0;   
> \> \>   
> \> \> while(movietexture\>=0)  
> \> \>   
> \> \> [movietexture] = Screen('GetMovieImage', win, movie, 0);  
> \> \>   
> \> \> if (movietexture\>0)  
> \> \> Screen('DrawTexture', win, movietexture);  
> \> \> Screen('Flip', win);  
> \> \> Screen('Close', movietexture);  
> \> \> movietexture=0;  
> \> \> end;  
> \> \>   
> \> \> [keyIsDown, secs, keyCode]=KbCheck;  
> \> \> if (keyIsDown==1)  
> \> \> if keyCode(KbName('ESCAPE'))  
> \> \> droppedframes=Screen('PlayMovie', movie, 0, 0, 0);  
> \> \> Screen('CloseMovie', movie);  
> \> \> break;  
> \> \> end;  
> \> \> end;  
> \> \> end;  
> \> \>   
> \> \> Screen('PlayMovie', movie, 0, 0, 0);  
> \> \> Screen('CloseMovie', movie);  
> \> \> end  
> \> \>   
> \> \>   
> \> \> Whenever I press ESC to stop playback, it gives the error message

that  

> \> \> the movie handle does not exist. It does not have any problem

when the  

> \> \> same code is used after the display while loop (no error then).

Any ideas?  

> \> \>   
> \> \> Thanks in advance,  
> \> \>   
> \> \> - Jeff  
> \> \>  
> \>
