miqueas1234567
miqueas1234567

Reputation: 11

MPMoviePlayerController repeat mode not working in viewDidLoad

It seems that I'm having a problem with repeatmodeone: it does not repeat the video.

This is the code for the video I have in the implementation:

- (void)viewDidLoad{

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Space Particle" ofType:@"mp4"]];


    MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    [self presentMoviePlayerViewControllerAnimated:playerController];
    [playerController.moviePlayer prepareToPlay];
    playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
    playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
    [MyView1 addSubview: playerController.view];


    [playerController.moviePlayer play];
    [playerController release];playerController=nil;
}

It works as an animated background with buttons above it. The video plays but when it finishes, it does not repeat.

I found out that, as an IbAction, it repeats, but as a viewDidLoad it doesn´t.

Note that the "MyView" outlet has been linked to a custom UIButton, and it´s in the button view where the movie plays.

The videos I'm using aren't large in size.

My objective is that the movie must repeat using the viewdidload method in order to auto play and repeat.

Please, is there anything I am doing wrong? Suggestions on how to solve it? Any help would be appreciated.

Upvotes: 0

Views: 4507

Answers (3)

etamina
etamina

Reputation: 23

It's been deleted by ARC after the viewDidLoad function finished. You should hold the MPMoviePlayerController instance as a class member. NSNotification also solves the issue because it retains the object. Making it an instance variable will make notification solution redundant.

Upvotes: 2

Mystery
Mystery

Reputation: 552

Try following code. This is working perfectly.

    NSURL *fileUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Video" ofType:@"mp4"]];
    MPMoviePlayerViewController *moviePlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:fileUrl];
    [moviePlayerController.moviePlayer prepareToPlay];
    [moviePlayerController.moviePlayer setRepeatMode:MPMovieRepeatModeOne];
    [moviePlayerController.moviePlayer setControlStyle:MPMovieControlStyleEmbedded];
    [self.view addSubview:moviePlayerController.view];

Upvotes: 6

SPopenko
SPopenko

Reputation: 116

The same issue. I solved it with the next steps: 1) Subscribe to the end playback notification

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

2) Start playback manually in moviePlayBackDidFinished method

Upvotes: 0

Related Questions