我有一个带有 5 个按钮的单 View 应用程序,当按下其中一个按钮时,播放器会向上滑动到原始 View 上并开始全屏播放视频(它应该如此)。
除了按下全屏/最小化图标(播放控件旁边的两个对角箭头指向彼此)外,一切都很好。按下此按钮时,带有五个按钮的原始 View 会在视频播放器上方向上滑动。问题是视频仍在原始 View 下播放。我真的很想消除全屏/最小化图标,但据我所知,这似乎不可能。所以...我在想,当按下全屏/最小化图标时,我可以使用观察者来收听我可以做我需要做的事情。我只是找不到任何关于如何做到这一点的可靠信息。任何帮助/方向将不胜感激。
这是我当前的代码...
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
}
- (void)moviePlayerWillExitFullscreen:(NSNotification *)theNotification {
MPMoviePlayerController *playerController = [theNotification object];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
[playerController stop];
[self dismissMoviePlayerViewControllerAnimated];
}
最佳答案
这一行导致你出现这种行为。
[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];
它与您的常规 presentModalViewController 方法非常相似。
它以模态方式呈现 Movieplayer 及其 View Controller 。所以这里的默认设置是
movieplayer.controlStyle = MPMovieControlStyleFullScreen
这是默认设置。
因此,当您按下这些对角线箭头时,它会退出该模式,并为此发出通知。但是您必须先设置一个观察者来收听该通知,就像您在电影结束时所做的那样。
你做到了
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
这添加了一个通知以观察电影完成通知。 要退出全屏模式,请再添加一个观察者,即这个..
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieExitFullScreen:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];
在添加 -(void) movieExitFullScreen:(NSNotification *)
选择器后,您应该可以继续使用了。希望能帮助到你。 :)
关于ipad - iOS 在全屏模式下使用 MPMoviePlayerViewController (iPad),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4027879/