tags:

views:

117

answers:

3

I've got a navigation view with a table view in it, listing some videos. When a row is selected, it loads MPMoviePlayerViewController and inits it with a video from file URL. When I go back to the table view, the movie is still playing. I tried getting the underlying MPMoviePlayerController and giving it a "pause" message in the viewDidDisappear method, but this doesn't seem to ever get called (NSLog statement in method never appears). So I'm sure there's a simple way to tell MPMoviePlayerController via MPMoviePlayerViewController to stop playing it's movie programmatically, right?

A: 

You need to register for some notifications. See the 'Notifications' section of the MPMoviePlayerController class reference:

http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html

In particular, register to receive MPMoviePlayerDidExitFullscreenNotification and MPMoviePlayerPlaybackDidFinishNotification and in your method that is called when these notifications are sent, stop the movie from playing by sending the 'stop' message.

Jake
None of the notifications appear to fire in the circumstance I'm looking at -- when the video player gets popped off the controller stack. See below for solution which did work.
Devin Ceartas
A: 

But what about when you want to stop downloading the video before it is finished playing. For example, when you go to a different screen.

For me, i try to stop the video when the videoWillDisappear method gets called. Yet, the video still downloads even when the current video is gone!

Tony
A: 

Simply needed to subclass MPMoviePlayerViewController, load the subclass from the table/navigation on selection, then add this to that subclass:

-(void)viewWillDisappear:(BOOL)animated {
    [self.moviePlayer stop];    
}
Devin Ceartas