将MPMoviewPlayerController添加到UIViewController以进行全屏播放旋转

时间:2012-07-10 07:47:21

标签: ios uiview

我有同样的问题: MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)

我认为这个问题的答案非常有用。然后我为此添加了一个UIViewController。 首先:youtubePlayer是一个MPMoviePlayerController,底层代码将youTubeView的框架发送到youtubePlayer并在youTubeView上显示youtubePlayer:

[youtubePlayer.view setFrame:youTubeView.bounds];
[youTubeView addSubview:youtubePlayer.view];

切换到FullScreen后,我想将youtubePlayer.view添加到新的UIViewController,然后它可以自动旋转:     playerFullScreen = [[UIViewController alloc] init];

[playerFullScreen.view addSubview:youtubePlayer.view];
[nav pushViewController:playerFullScreen animated:NO];

但是屏幕变白,视频没有显示,我该怎么办?

1 个答案:

答案 0 :(得分:0)

您不需要使用UIViewController; MPMoviePlayerViewController效果很好,它有自己的功能,可以像YouTube一样以模态方式呈现视频(我认为)。而不是addSubview,请尝试使用setView

我花了很长时间研究这个,以下工作完美。

moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

//Calls for movie playback once video is finished
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];
playerView = [[MPMoviePlayerViewController alloc]init];
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[playerView setView:moviePlayer.view];

[moviePlayer.view setFrame: self.view.bounds];  // player's frame must match parent's

[self presentMoviePlayerViewControllerAnimated:playerView];

[moviePlayer play];
NSLog(@"playing video view");

并且在解雇其电话时

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
    MPMoviePlayerController *player = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self      
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];

    [self dismissMoviePlayerViewControllerAnimated];

    NSLog(@"removed video view");
}