0

I have the same question with : MPMoviewPlayerController fullscreen playback rotation with underlying UIViewController with portrait mode only (rotation disallowed)

and I think the answer of this question is very useful. Then I add a UIViewController for this purpose. First: youtubePlayer is a MPMoviePlayerController, the under code send youTubeView's frame to youtubePlayer and show youtubePlayer on youTubeView:

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

After switch to FullScreen, I want to add youtubePlayer.view to a new UIViewController, then it can auto-rotation: playerFullScreen = [[UIViewController alloc]init];

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

but the screen turn white, video not show up, what should I do ?

Community
  • 1
  • 1
kevin young
  • 941
  • 2
  • 10
  • 22

1 Answers1

0

You don't need to use UIViewController; MPMoviePlayerViewController works just as fine, and it has its own functions to present videos modally, just like YouTube (I think). Also instead of addSubview, try using setView:

I spent a long time researching this and the following works perfectly.

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");

and when dismissing its calls

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

    [self dismissMoviePlayerViewControllerAnimated];

    NSLog(@"removed video view");
}
Hailei
  • 42,163
  • 6
  • 44
  • 69
Diremage
  • 200
  • 1
  • 2
  • 10