iphone - 强制 MPMoviePlayerController 以横向模式播放视频
我有一个仅纵向模式的应用程序,但是当用户播放视频时,我希望它以全屏横向模式播放(视频播放器在纵向模式下看起来不太好)。我是这样玩的:
[self.view addSubview:myMoviePlayer.view];
[self.myMoviePlayer setFullscreen:YES animated:YES];
[self.myMoviePlayer play];
完成这个任务的最佳方法是什么?
I have an app that is portrait mode only, but when the user plays a video I want it to play in fullscreen landscape mode (the video player doesn't look good in portrait mode). I'm playing it like this:
[self.view addSubview:myMoviePlayer.view];
[self.myMoviePlayer setFullscreen:YES animated:YES];
[self.myMoviePlayer play];
What's the best way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
阅读这篇文章:
主要思想是:
Read this article:
http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html
The main idea is:
我的应用程序非常简单,使用 UINavigationController 作为根视图控制器,显示主导航屏幕和一些详细信息屏幕。由于布局限制,主屏幕不支持旋转,并且为了保持一致性,详细信息屏幕(简单地推送到导航控制器的堆栈上)也不支持旋转。但是,某些详细信息屏幕包含视频链接,并且视频需要以纵向模式显示。该应用程序使用 MPMoviePlayerController 以模态方式显示播放器。
我刚刚遇到了类似的问题,并尝试了上面的解决方案,该解决方案将仿射变换应用于 MPMoviePlayerController 的视图,但问题是状态栏继续以纵向模式显示,并与模式电影播放器视图重叠(在左侧,如果按照上面的旋转查看)。我尝试了一些方法但没有成功:
隐藏状态栏。这不起作用,因为玩家存在于自己的世界中,无论如何都会继续显示状态栏。我找不到办法让它消失。
显式设置状态栏方向。我不确定为什么这不起作用,但我怀疑这是因为我在 info.plist 中指出仅支持纵向,因此无法进行更改。
Net-net,以上对我不起作用。同样,b/c Apple 告诫开发人员将 MPMoviePlayerController 视为不透明,并且(特别是使用转换方法)我违反了这一点。
最后,我找到了一个对我有用的更简单的解决方案:
子类 UINavigationController,并重写适当的 shouldAutorotate 方法,以便仅支持纵向(请参阅 此解决方案,以及如何在 iOS <6 和 iOS6 中同时执行此操作)。
这是有效的,因为:
虽然我指出应用程序支持自动旋转,但我在包含我正在渲染的所有视图的 UINavigationController 子类处将其切断......所以一切都保持纵向,除了for:
MPMoviePlayerController 是在 NavigationController 之上以模态方式呈现的,并且存在于它自己的世界中。因此,它可以自由地关注 info.plist 中的内容,并自行旋转。
有很多关于如何以模态方式呈现播放器的示例,但为了快速参考,这是我的代码:
My app is quite simple, with a UINavigationController as the root view controller which displays a main navigation screen, and a few detail screens. The main screen does not support rotation due to layout constraints, and for consistency the detail screens (which are simply pushed onto the navcontroller's stack) don't either. However, some of the detail screens contain links to videos, and the videos need to display in portrait mode. The app displays the player modally using MPMoviePlayerController.
I just had a similar issue, and tried the solution above which applies an affine transform to the MPMoviePlayerController's view, but the problem was that the status bar continued to display as in portrait mode, and overlapped the modal movie player view (on the left, if viewed in according to the rotation above). I tried a couple of things to no avail:
Hiding the status bar. This didn't work, because the player exists in its own world, and goes ahead and presents the status bar anyway. I couldn't find a way to make this go away.
Explicitly setting the status bar orientation. I'm not sure exactly why this didn't work, but I suspect that it was because I'd indicated in my info.plist that only portrait was supported and was therefore cut off from making changes.
Net-net, the above didn't work for me. Just as well, b/c Apple admonishes devs to treat the MPMoviePlayerController as opaque, and (especially with the transform method) I was violating this.
In the end, I found a simpler solution that worked for me:
In the info.plist, I indicated that all orientations (except for upside down, so the standard iPhone idiom) were supported.
Subclass UINavigationController, and override the appropriate shouldAutorotate methods so that only Portrait is supported (see this solution, among others, for how to do this in iOS <6 and iOS6 concurrently).
This worked because:
While I'd indicated that autorotation is supported by the app, I cut it off at the UINavigationController subclass which contains all of the views I'm rendering... so everything remains portrait, except for:
The MPMoviePlayerController is being presented modally, atop the NavigationController, and lives in its own world. Therefore it's free to pay attention to what's in the info.plist, and rotate all by itself.
There are a bunch of examples for how to present the player modally, but for quick reference, here's my code:
对于全屏播放,请使用 MPMoviePlayerViewController,然后要使其以横向格式启动和播放,请使用 MPMoviePlayerViewController 类上的“shouldAutorotateToInterfaceOrientation”方法。
它看起来像这样:
For full screen playback use MPMoviePlayerViewController and then to make it launch and play in landscape format use the "shouldAutorotateToInterfaceOrientation" method on the MPMoviePlayerViewController class.
It looks like this:
我遇到了同样的情况,但我使用的是 iOS 6 和基于 NavController 的项目。有趣的是托管 MPMoviePlayerController 的 ViewController 我不想旋转,但我希望其中的视频旋转。
我只是根据设备方向根据需要手动旋转 MPMoviePlayerController。 _videoView 是 ViewController 的 MPMoviePlayerController 属性。例如,我只是将所需的宽度和高度硬编码为 16x9 的宽高比,因为我打算将该视频上传到 youtube。
我还在视图出现后调用 updateVideoRotationForCurrentRotationWithAnimation ,以便它具有正确的初始方向。
I had the same situation, but I am using iOS 6 and a NavController based project. What makes that interesting is the ViewController that is hosting the MPMoviePlayerController I don't want rotated, but I wanted the video within it to be rotated.
I just manually rotate the MPMoviePlayerController as needed based on the devices orientation. _videoView is a MPMoviePlayerController property of the ViewController. For the example, I just hard coded the desired width and height to a 16x9 aspect ratio as I intend this video to be uploaded to youtube.
I also call updateVideoRotationForCurrentRotationWithAnimation after view did appear so it has the correct initial orientation.
我使用以下代码仅使用 Movieplayer 的横向模式。
I use the following code to work with ONLY LANDSCAPE mode for Movieplayer.