我正在使用 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];
}
这是一个屏幕。第一个是没有按下全屏按钮,第二个是在按下它之后。
最佳答案
您必须将 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/