Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController: How can I make my video loop?

Thank you in advance for any help, I am a newbie and would appreciate any help here.. I have this code to play a movie and it works great. Can somebody PLEASE tell me how to make this movie loop and replay from the beginning non stop ( any code would help). Also I would like to know how to play 2 movies, one after the other, preferably with a fade or smooth transition. Thank you for any help

#import "MyAppViewController.h"

@implementation MyAppViewController

-(IBAction)button:(id)sender{
 NSString *path = [[NSBundle mainBundle]
       pathForResource:@"mymovie" ofType:@"mp4"];

 player = [[MPMoviePlayerViewController alloc]
     initWithContentURL:[NSURL fileURLWithPath:path]];

 [self presentMoviePlayerViewControllerAnimated:player];

}
like image 722
Jay L Avatar asked Jan 02 '11 21:01

Jay L


3 Answers

Set the repeatMode property of your MPMoviePlayerController to MPMovieRepeatModeOne

player = [[MPMoviePlayerViewController alloc]
          initWithContentURL:[NSURL fileURLWithPath:path]];
player.moviePlayer.repeatMode = MPMovieRepeatModeOne;
like image 198
Jacob Relkin Avatar answered Oct 18 '22 02:10

Jacob Relkin


MPMovieRepeatModeOne is nice but it doesn't loop the video very smoothly. Try this below (copied from another post) :

(I just got this working on my iPad 3 running iOS 5.1.1, base SDK iOS 5.1.)

When setting up the movie player, set the repeat mode to MPMovieRepeatModeNone then add the notification

[[NSNotificationCenter defaultCenter] addObserver:self
            selector:@selector(moviePlayerDidFinish:)
            name:MPMoviePlayerPlaybackDidFinishNotification
                            object:self.moviePlayer];

Then set up your selector to filter when the movie finishes playing:

- (void)moviePlayerDidFinish:(NSNotification *)note
{
    if (note.object == self.moviePlayer) {
        NSInteger reason = [[note.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
        if (reason == MPMovieFinishReasonPlaybackEnded)
        {
            [self.moviePlayer play];
        }
    }
}
like image 20
Jeeri Avatar answered Oct 18 '22 02:10

Jeeri


For the timer you can create an Int variable that has the value of your slider and then use a performSelector afterDelay:

int delayInt = 8; // Substitute the 8 for the value of your slider
[self performSelector:@selector(myMethod) withObject:nil afterDelay:delayInt];

And then in your "myMethod"

-(void) myMethod{
//the code to stop your player and remove view controller
}
like image 1
Ricardo Contreras Avatar answered Oct 18 '22 02:10

Ricardo Contreras