Matt Langtree

Restarting a Video in MPMoviePlayerController

I’m working on a project where the standard controls provided by MPMoviePlayerController aren’t matching the existing styling of the app design. I need to provide a custom rewind button for the movie I’m auto- playing for the user. When the video finishes it needs to hide the modal movie view controller, and I’m handling this with the MPMoviePlayerPlaybackDidFinishNotification notification. The best way I can think of doing the rewind without triggering the view to dismiss is with the following code..

Restart video in iOS
1
2
3
4
5
6
7
8
9
10
11
12
- (void)restartVideo
{
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];
    [mp stop];
    [mp play];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];
}

Update: Thanks to @avenjamin for suggesting that I call the method -restartVideo rather than -rewindVideo as the meaning was slightly incorrect.