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.
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..
.
Hello it can be done using what jbandes said
[[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:theMoviePlayer.moviePlayer];
精彩评论