Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPad SDK: How to hook into done button of MPMoviePlayerViewController?

Tags:

ipad

I am creating an iPad add and I am using a MPMoviePlayerViewController to playback a video.

The video is occupying the entire iPad screen like this.

playerViewController.view.frame = self.view.frame;

I need a way for the user to be able to press a button to go to a different screen.

I notice that automagically a done button appears in the nav controller when I create a MPMoviePlayerViewController.

My questions:

a.) Is there anyway to hook into the existing done button? Basically I just want to dismiss the view controller.

b.) If that won't work. How can I add my own custom button? As I mentioned above, the MPMoviePlayerViewController is occupying the entire screen. One idea I had was to create the MPMoviePlayerViewController in a frame and leave a bit of vertical space so I could add my own tool bar.

I would prefer suggestions on how to implement a.)?

If that is not possible, maybe some suggestions on how dismiss the MPMoviePlayerViewController by way of some button press?

All help appreciated.

like image 263
butchcowboy Avatar asked Jul 24 '10 20:07

butchcowboy


2 Answers

From the docs:

the Done button causes movie playback to pause while the player transitions out of fullscreen mode. If you want to detect this scenario in your code, you should monitor other notifications such as MPMoviePlayerDidExitFullscreenNotification.

So, try observing this notification:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerDidExitFullscreen:)
                                             name:MPMoviePlayerDidExitFullscreenNotification
                                           object:nil];

And later:

- (void)moviePlayerDidExitFullscreen:(NSNotification *)theNotification {
    // do whatever you need to...
}

Edit: I think I misread your question. What you want is the method
-dismissMoviePlayerViewControllerAnimated

I assume you're presenting it using -presentMoviePlayerViewControllerAnimated:? You can add a button using moviePlayer.navigationItem.rightBarButtonItem (or left, or whichever). Set this button's target to your view controller, and intercept that action to call -dismiss...

like image 110
jtbandes Avatar answered Oct 27 '22 17:10

jtbandes


Hello it can be done using what jbandes said

[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMoviePlayer.moviePlayer];
like image 30
user281300 Avatar answered Oct 27 '22 17:10

user281300