我的代码播放视频文件时遇到问题。每当我以全屏模式播放文件时,播放都不会占用我的所有屏幕。以下是相关代码:
NSURL *url = [NSURL fileURLWithPath:@"Somefile.mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES];
moviePlayer.view.frame = self.switchView.frame;
[self.switchView addSubview:moviePlayer.view];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playbackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:moviePlayer];
[moviePlayer prepareToPlay];
[moviePlayer play];
以下是我得到的输出:
答案 0 :(得分:7)
选项A:改为使用MPMovieViewController
并使用presentMoviePlayerViewControllerAnimated:
以模态方式显示。
选项B:确保您的switchView(用于添加moviePlayer视图)实际占用整个屏幕。
选项C:使用负垂直偏移重新调整moviePlayer视图的帧,直到它适合 - 例如:moviePlayer.view.frame = CGRectMake(0.0f, -20.0f, 320.0f, 480.0f);
注意:MPMoviePlayerController 始终在使用控件样式MPMovieControlStyleFullscreen
时显示状态栏,无论应用程序的其余部分如何处理状态栏。
答案 1 :(得分:1)
使用以下方法更改播放器的controlstyle属性: - (void)applyUserSettingsToMoviePlayer
player.controlStyle = MPMovieControlStyleFullScreen导致上述问题,将其更改为MPMovieControlStyleEmbedded,看看是否有效。