Screen('PlayMovie') issues

Hi all, 

I am trying to play a video backwards and forwards depending on key press. For example, if I press Right Arrow, I want to step forward in the video, and if I press Left Arrow I want to reverse the video. 

The issue is that my video keep on closing after Forward Step >> Backward Step >> Forward Step and I do not understand why. 

I would be grateful if anyone could help. 

Thank you!

N

    % Open Movie file
    [movie, duration, fps]= Screen('OpenMovie', win, movieName);
    
    % Playback loop: Runs until end of movie or keypress:
    while 1
        
        % Check which key is pressed: 
        [~, ~, keyCode] = KbCheck;
        
        % Valid texture returned? A negative value means end of movie reached:
        if tex <= 0 
            
            % We're done, break out of loop:
            break;
        
        % Stop loop if ESC is pressed:
        elseif keyCode(41) == 1  %Windows 27; Mac 41
            
             % We're done, break out of loop:
            break;
        
        % Play movie backward while LeftArrow is pressed:
        elseif keyCode(80) %Windows 37; Mac 80
            
            % Start backward playback:
            Screen('PlayMovie', movie, -1);
            
            % Get next video frame:
            GetNextFrame
            
            % Stop playback:
            Screen('PlayMovie', movie, 0);
            disp(timeStamp)
        
        % Play movie forward while RightArrow is pressed:    
        elseif keyCode(79) == 1  %Windows 39; Mac 79
                    
            % Start forward playback:
            Screen('PlayMovie', movie, 1);
            
            % Get next video frame:
            GetNextFrame
            
            % Stop playback:
            Screen('PlayMovie', movie, 0);
            disp(timeStamp)
       
        % IF end: 
       end

    % WHILE end:
    end

    % Close movie:
    Screen('CloseMovie', movie);




Natasa Ganea
Hi,

the code is incomplete, nothing one could simply run, so hard to judge, also you don't provide any output like error messages it may produce. Also look into KbName() for how to get operating-system independent mapping of key names to keycodes.

But in general that approach of starting playback, fetching a single frame, then stopping playback again is likely fragile with various movie formats, and very inefficient. Are your movies very long or with sound? Otherwise for short movies i'd use the approach from LoadMovieIntoTexturesDemo.m to load the movie into memory as a set of textures, then you can easily navigate between them like that demo shows.

Another approach that would likely work better is to not start/stop movie playback at all, but use the 'forTimeIndex' parameter in Screen('GetMovieImage',...) to select a specific movie frame by its time in the movie. See also 'SetMovieTimeIndex' and 'GetMovieTimeIndex' for navigating inside a movie.

-mario


XXXIn PSYCHTOOLBOX@yahoogroups.com, <n_k_rush@...> wrote :

Hi all, 

I am trying to play a video backwards and forwards depending on key press. For example, if I press Right Arrow, I want to step forward in the video, and if I press Left Arrow I want to reverse the video. 

The issue is that my video keep on closing after Forward Step >> Backward Step >> Forward Step and I do not understand why. 

I would be grateful if anyone could help. 

Thank you!

N

    % Open Movie file
    [movie, duration, fps]= Screen('OpenMovie', win, movieName);
    
    % Playback loop: Runs until end of movie or keypress:
    while 1
        
        % Check which key is pressed: 
        [~, ~, keyCode] = KbCheck;
        
        % Valid texture returned? A negative value means end of movie reached:
        if tex <= 0 
            
            % We're done, break out of loop:
            break;
        
        % Stop loop if ESC is pressed:
        elseif keyCode(41) == 1  %Windows 27; Mac 41
            
             % We're done, break out of loop:
            break;
        
        % Play movie backward while LeftArrow is pressed:
        elseif keyCode(80) %Windows 37; Mac 80
            
            % Start backward playback:
            Screen('PlayMovie', movie, -1);
            
            % Get next video frame:
            GetNextFrame
            
            % Stop playback:
            Screen('PlayMovie', movie, 0);
            disp(timeStamp)
        
        % Play movie forward while RightArrow is pressed:    
        elseif keyCode(79) == 1  %Windows 39; Mac 79
                    
            % Start forward playback:
            Screen('PlayMovie', movie, 1);
            
            % Get next video frame:
            GetNextFrame
            
            % Stop playback:
            Screen('PlayMovie', movie, 0);
            disp(timeStamp)
       
        % IF end: 
       end

    % WHILE end:
    end

    % Close movie:
    Screen('CloseMovie', movie);




Natasa Ganea