Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController rotating in full screen while the parent View Controller only supports portrait orientation

this question is only one part of my problem. I am implementing iOS6 rotation and orientation support for my existing application.

So I have a ViewController that contains a MPMoviePlayerController embedded in ViewController view ( my application requires it ). User can play the video and see it in the embedded view or click on full screen button using the default player controls and player goes to full screen mode.

Now I have restricted the view controller to only support portrait orientation using the new rotation APIs provided by iOS6.

// New Autorotation support.
- (BOOL)shouldAutorotate;
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

this works pretty well. the ViewController only supports portrait and user play the movie in embedded view.

Now the problem comes, when User goes into full screen mode. In full screen mode, the movie is keep on rotating, when i rotate the simulator/device. When i rotate the device while movie being played in full screen mode with breakpoints in shouldAutorotate and supportedInterfaceOrientations , it still comes in these both methods which return NO and UIInterfaceOrientationMaskPortrait respectively, but still the movie is rotating ...

Why is this happening? .... this is one part of my question ... the 2nd part is I want the movie to enter in landscape mode when the user goes to full-screen mode. and I want the movie player to lock in landscape mode until user presses the DONE button.

Please help ....

like image 289
g.revolution Avatar asked Nov 27 '12 09:11

g.revolution


3 Answers

you can try below function in AppDelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{

}

you can make condition here for both mode.

such as if media player is in full screen then

return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;

otherwise return UIInterfaceOrientationMaskPortrait;

i have not tried it but i think, it should work in your case.

thanks

like image 151
Hindu Avatar answered Nov 18 '22 13:11

Hindu


For clarity, here is the complete code (it ALL goes inside your app delegate):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(willExitFullscreen:)
                                                 name:MPMoviePlayerWillExitFullscreenNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(willEnterFullscreen:)
                                             name:MPMoviePlayerWillEnterFullscreenNotification
                                           object:nil];
}

- (void)willEnterFullscreen:(NSNotification*)notification
{
    NSLog(@"willEnterFullscreen");
    isFullScreen = YES;
}

- (void)willExitFullscreen:(NSNotification*)notification
{
    NSLog(@"willExitFullscreen");
    isFullScreen = NO;
}

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if (isFullScreen)
        return UIInterfaceOrientationMaskLandscapeLeft;
    else
        return UIInterfaceOrientationMaskPortrait;
}

isFullScreen is a BOOL to be declared in AppDelegate.h

like image 35
etayluz Avatar answered Nov 18 '22 13:11

etayluz


I would suggest to use a MPMoviePlayerViewController instead. Subclass it and implement the supportedInterfaceOrientations method and return UIInterfaceOrientationMaskLandscape.

You might also have to implement the shouldAutorotateToInterfaceOrientation: method.

See the class reference: MPMoviePlayerViewController

Edit: You might also take a look at this post: iphone - force MPMoviePlayerController to play video in landscape mode

like image 1
Tobi Avatar answered Nov 18 '22 13:11

Tobi