7

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.

butchcowboy
  • 575
  • 1
  • 8
  • 16

2 Answers2

10

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...

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • I really just need a way to allow the user to close the ViewController. In fact, I just want to: [self dismissModalViewControllerAnimated:YES]; I tried registering for MPMoviePlayerDidExitFullscreenNotification which works fine but does not have the desired effect. Ideas? – butchcowboy Jul 24 '10 at 20:41
  • I tried adding a button and then assigning to mp.navigationitem.rightBarButtonItem but it did not show up. Does anyone have an example of this working? – butchcowboy Jul 27 '10 at 14:06
  • Anyone found a solution for this ? Been googling everywhere...How can I listen to the modal view being dismissed aprt from extending the controller and overriding the dissmiss method? – user281300 Sep 30 '10 at 13:04
  • when control style is set to MPMovieControlStyleFullscreen, the Done button does not trigger the MPMoviePlayerDidExitFullscreenNotification notification. – Max MacLeod Jun 28 '11 at 15:25
  • @MaxMacLeod when control style is set to MPMovieControlStyleFullscreen, then can we get we get notify clicking on Done button any how – Kamar Shad Apr 26 '12 at 12:37
8

Hello it can be done using what jbandes said

[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMoviePlayer.moviePlayer];
user281300
  • 1,427
  • 2
  • 19
  • 31
  • that also gets called when the movie finishes playing without having pushed the Done button – Max MacLeod Jun 28 '11 at 15:17
  • @ Max MacLeod user presentMoviePlayerViewControllerAnimated then the MPMoviePlayerDidExitFullscreenNotification will be raised. – Arun Dev Feb 08 '12 at 01:12
  • Awesome! That works on the `MPMoviePlayerViewController` as well when the done button is pressed. The `MPMoviePlayerWillExitFullscreenNotification` is not firing there. – Michael Kork. May 24 '13 at 09:43