我有一个带有5个按钮的单个视图应用程序,当按下其中一个按钮时,播放器在原始视图上滑动并开始全屏播放视频(应该如此)。
除了按下全屏/最小化图标(播放控件旁边的两个对角箭头指向对方)之外,一切都很好用。按此按钮时,带有五个按钮的原始视图会在视频播放器上滑动。问题是视频仍在原始视图下方播放。我真的想要消除Fullscreen / Minimize图标,但从我可以看出,这似乎不可能。所以......我在思考,我可以使用观察者来听取按下Fullscreen / Minimize图标的时间,我可以做我需要做的事情。我找不到任何关于如何做到这一点的可靠方法。任何帮助/方向将不胜感激。
这是我目前的代码......
-(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];
}
答案 0 :(得分:2)
这一行导致了你的行为。
[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];
它与您的常规presentModalViewController方法非常相似。
它提供了Movieplayer及其视图控制器Modally。所以这里的默认设置是
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 *)
选择器添加{{1}}选择器之后,您应该很高兴。希望能帮助到你。 :)
答案 1 :(得分:1)
将此行放在MPMoviePlayer的init之后:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
答案 2 :(得分:1)
我认为你在想要删除它的方法中添加了观察者。
你想要这个
MPMoviePlayerController *playerController = [theNotification object];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerWillExitFullscreen:)
name:MPMoviePlayerWillExitFullscreenNotification
object:nil];
在playVideo()
中和这个
[[NSNotificationCenter defaultCenter] removeObserver:self
name:name:MPMoviePlayerWillExitFullscreenNotificationn
object:nil];
在moviePlayerWillExitFullscreen方法中。
答案 3 :(得分:0)
我确实找到了一个解决方案,而我缺乏知识使我处于这样一种情况,即我不完全理解为什么它以这种方式工作。我为没有彻底的推理而道歉。在我的原始代码中... MPMoviePlayerWillExitFullscreenNotification没有回答分接头。对于MPMoviePlayerDidExitFullscreenNotification也是如此。回答的是MPMoviePlayerPlaybackDidFinishNotification。以下是知道MPMoviePlayerPlaybackDidFinishNotification正在运行并且还应用于Fullscreen / Embed印刷机的工作代码。
-(IBAction)playvideo {
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Megamind" ofType:@"mov"]];
MPMoviePlayerViewController * playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self presentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController *)playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
NSLog(@"playvideo");
}
- (void)movieFinishedPlayback:(NSNotification*)notification {
MPMoviePlayerController *playerController = [notification object];
[playerController pause];
[self dismissMoviePlayerViewControllerAnimated];
}