0

我有同样的问题: MPMoviewPlayerController 全屏播放旋转,底层 UIViewController 仅具有纵向模式(不允许旋转)

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

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

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

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

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

4

1 回答 1

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");
}
于 2012-07-23T07:55:46.600 回答