[英]How to get MPMoviePlayerController's view to resize on rotate when it is not full-screen
Our client wants to display a video in a view on the screen. 我们的客户想要在屏幕上的视图中显示视频。 The code creates an MPMoviePlayerController and installs it's view as a subview of it's container view, just like the docs say to do:
该代码创建一个MPMoviePlayerController并将其视图安装为其容器视图的子视图,就像文档中说的那样:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: myVideoURL];
[moviePlayer prepareToPlay];
[moviePlayer.view setFrame: _videoPlaybackContainerView.bounds];
moviePlayer.controlStyle = MPMovieControlStyleNone;
[_videoPlaybackContainerView addSubview: moviePlayer.view];
I have the container view set up to resize when the view controller's content view resizes due to auto-rotation. 当视图控制器的内容视图由于自动旋转而调整大小时,我将容器视图设置为调整大小。
If I rotate the device while the video is playing you can see that the container view resizes, but the video does not. 如果我在播放视频时旋转设备,可以看到容器视图的大小已调整,但视频没有调整。 It gets clipped, doesn't center in the view, etc.
它被裁剪,不在视图中居中,等等。
I guess I could try to set up the resizing masks on the player's view (we're not using AutoLayout for this project) but the docs do say to treat the player's view as an opaque structure, and I'm not sure if mucking with it's resize masks violates that or not. 我想我可以尝试在播放器的视图上设置调整大小的蒙版(我们不在此项目中使用AutoLayout),但是文档确实说过将播放器的视图视为不透明结构,并且我不确定是否与它的大小调整蒙版是否违反该要求。
I did a fair amount of searching for help on the net, but all the other discussions I could find either dealt with the movie player view CONTROLLER (a different animal) or with full-screen display, which is also different. 我在网络上进行了大量的搜索以寻求帮助,但是我能找到的所有其他讨论都涉及电影播放器视图CONTROLLER(一种不同的动物)或全屏显示,这也有所不同。
I've solved it. 我已经解决了
I set the fill mode to aspect fit: 我将填充模式设置为适合方面:
moviePlayer.scalingMode = MPMovieScalingModeAspectFit moviePlayer.scalingMode = MPMovieScalingModeAspectFit
Then when I get a didRotateFromInterfaceOrientation call in my view controller, I resize my container view and simply change the frame of the movie player's view explicitly. 然后,当我在视图控制器中收到didRotateFromInterfaceOrientation调用时,我将调整容器视图的大小,并简单地显式更改电影播放器视图的框架。
I had to do some fairly gnarly math to get my video container view to resize to the largest size that exactly preserves the aspect ratio though. 我不得不做一些相当粗糙的数学运算,以使我的视频容器视图调整为最大尺寸,以完全保留宽高比。 That probably would have been straightforward if we were using AutoLayout.
如果我们使用的是AutoLayout,那可能会很简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.