Search code examples
iosobjective-cmpmovieplayercontrollerscreen-orientation

MPMoviePlayerViewController in landscape / all orientations


My questions is really simple, tutorials and answers didn't fix my problem.

I have an app with settings:

enter image description here

I want support only Portrait/Upside Down orientations in all my viewControllers except when I want to play video via:

MPMoviePlayerViewController

Here is code:

MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:[Videos videoURL:video.hash]];
if (mp) {
    isVideoPlaying = YES;

    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(videoFinishedPlaying:)
     name:MPMoviePlayerPlaybackDidFinishNotification
     object:mp.moviePlayer];

    [self presentMoviePlayerViewControllerAnimated:mp];
    mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
    [mp.moviePlayer play];
    [mp release];
}

When MPMoviePlayerViewController plays video I want support all orientations.
Need your help.


Solution

  • You should permit rotation by the following:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
         // Return YES for supported orientations
    }
    

    IOS 6:

    - (NSUInteger)supportedInterfaceOrientations
    {
    
        return UIInterfaceOrientationMaskAll;
    }
    

    put the code in the .m file where you call the player