iOS 在全屏模式下使用 MPMoviePlayerViewController (iPad)
我有一个带有 5 个按钮的单视图应用程序,当按下其中一个按钮时,播放器会在原始视图上向上滑动并开始全屏播放视频(正如它应该的那样)。
除了按全屏/最小化图标(播放控件旁边的两个对角箭头相互指向)外,所有功能都很好。按下此按钮时,带有五个按钮的原始视图会在视频播放器上向上滑动。问题是视频仍在原始视图下播放。我真的很想消除全屏/最小化图标,但据我所知,这似乎不可能。所以...我在想,当按下全屏/最小化图标时,我也许可以使用观察者来收听,并且我可以做我需要做的事情。我只是找不到任何关于如何做到这一点的可靠信息。任何帮助/指导将不胜感激。
这是我当前的代码...
-(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];
}
I have a single view app with 5 buttons and when one of the buttons is pressed, the player slides up over the original view and begins playing the video in fullscreen (as it should).
All works great with the exception of when pressing the Fullscreen/Minimize icon (the two diagonal arrows pointing to each other next to the play back controls). When pressing this, the original view with the five buttons slides up over the video player. The problem is the video is still playing underneath the original view. I would really like to eliminate the Fullscreen/Minimize icon but from I can tell, that does not seem possible. So... I am thinking, I might be able to use an observer to listen to when the Fullscreen/Minimize icon is pressed and I can do what I need to. I just can not find anything solid on how to do this. Any help/direction would be greatly appreciated.
Here is my current code...
-(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这条线导致了你的行为。
它与常规的 presentModalViewController 方法非常相似。
它以模态方式呈现电影播放器及其视图控制器。所以这里的默认设置就是
默认设置的。
因此,当您按下这些对角箭头时,它会退出该模式,并发出通知。但是您必须首先设置一个观察者来监听该通知,就像电影完成时所做的那样。
您做了
这会添加一个通知以观察电影完成通知。
要退出全屏模式,请再添加一个观察者,即:
添加
-(void) movieExitFullScreen:(NSNotification *)
选择器后就可以了。希望有帮助。 :)This line is causing you that behaviour.
It is pretty much similar to your regular presentModalViewController method.
It presents the Movieplayer and its view controller Modally. So the default settings here are
which are set up by default.
So when you press those diagonal arrows, it exits that mode, and gives a notification for that. But you have to setup an observer first to listen to that notifcation as you did for movie finished.
You did
This adds a notification to observe for movie completion notifications.
For exiting full screen mode add one more observer that is this..
And you should be good to go after adding the
-(void) movieExitFullScreen:(NSNotification *)
selector for the same. Hope it helps. :)将此行放在 MPMoviePlayer 的 init 之后:
Put this line just after the init of your MPMoviePlayer :
我认为您正在将观察者添加到您想要删除它的方法中。
您希望
在 playVideo() 中
使用它,
在 moviePlayerWillExitFullscreen 方法中使用它。
I think you're adding the observer in the method where you want to be REMOVING it.
You want this
in the playVideo()
and THIS
in the moviePlayerWillExitFullscreen method.
我确实找到了解决方案,但由于缺乏知识,我无法完全理解它为什么会这样工作。我很抱歉没有进行彻底的推理。在我的原始代码中... MPMoviePlayerWillExitFullscreenNotification 没有响应点击。对于 MPMoviePlayerDidExitFullscreenNotification 也是如此。回答的是 MPMoviePlayerPlaybackDidFinishNotification。这是工作代码,了解 MPMoviePlayerPlaybackDidFinishNotification 正在工作并且也应用于全屏/嵌入印刷机。
I did find a solution and my lack of knowledge put me in a situation where I do not fully understand why it works this way. My apologies for not having a thorough reasoning. In my original code... the MPMoviePlayerWillExitFullscreenNotification was not answering to taps. This is true for MPMoviePlayerDidExitFullscreenNotification as well. What was answering was MPMoviePlayerPlaybackDidFinishNotification. Here is teh working code in knowing that the MPMoviePlayerPlaybackDidFinishNotification was working and also applied to the Fullscreen/Embed presses.