iphone - iOS - 强制全屏视频

标签 iphone ios ipad mpmovieplayercontroller

我正在使用 MPMoviePlayerViewController。当视频加载并开始播放时,它不会填满整个屏幕。我必须按下右上角的全屏按钮才能实现。如果我使用 MPMoviePlayerController,我根本无法让它填满屏幕。

有什么方法可以通过代码使用 MPMoviePlayerViewController 让我的视频全屏显示而无需按全屏按钮?

我知道我在这里使用的是私有(private) API,不过没关系,它只是为了演示。

代码:

- (void)viewDidLoad
{
[super viewDidLoad];


[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];
NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"phatpad" ofType:@"mov"];

if (moviePath)
{
    NSURL *url = [NSURL fileURLWithPath:moviePath];
    player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
}

player.view.frame = self.view.frame;

[self.view addSubview: player.view];

}

这是一个屏幕。第一个是没有按下全屏按钮,第二个是在按下它之后。 enter image description here

最佳答案

您必须将 fullscreen 属性设置为 true 并将 scallingMode 设置为纵横比填充,如下所示:

if (moviePath)
{
    NSURL *url = [NSURL fileURLWithPath:moviePath];
    player = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
    player.moviePlayer.fullscreen = YES;
    player.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
}

我已经在家里测试过并且有效,所以我希望你也能。

关于iphone - iOS - 强制全屏视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7179802/

相关文章:

iPad闪存驱动器的预期生命周期?

iphone - UITableView向下滚动时如何实现 "Loading"?

iphone - 使用核心音频实现后处理低通滤波器

ios - 如何检查 CocoaPods 框架的版本

iOS响应物理键盘事件和UIInternalEvent

ios - UIWebView 和 NSURLConnection 共享 cookie 存储吗?

javascript - 如何在 Windows 7 中测试与 Ipad 一起使用的网站

ios - 不允许在 App 内购买

iphone - scrollToRowAtIndexPath :atScrollPosition:animated scrolling too slow

html - 网站 build 中的 iPad 缩放问题