1

I've got a MPMoviePlayer working. It is designed to show a postage-stamp size movie as a subview in the view. When the phone is rotated into landscape, it goes into full screen mode. And when the phone is in portrait it goes into postage-stamp portrait mode.

The only problem is when I press Done when in landscape mode, it stays in landscape, with the postage stamp sized movie, rather than kick back into portrait..

Here's some of my code:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 


    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation ==  UIInterfaceOrientationLandscapeLeft) {
        [moviePlayerController setFullscreen:YES animated:YES];
    } else
    {
        [moviePlayerController setFullscreen:NO animated:YES];

    }


}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

        return interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft;

}

How would I get it to kick into portrait mode after pressing Done?

cannyboy
  • 24,180
  • 40
  • 146
  • 252

4 Answers4

2

@cannyboy...you just need to use below method in your APPDelegate.m if your application only works with portrait mode

- (NSUInteger) application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if ([[window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]])
{
    //NSLog(@"in if part");
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
    //NSLog(@"in else part");
    return UIInterfaceOrientationMaskPortrait;
}}
Shubham
  • 570
  • 3
  • 12
  • If I use this code, everything works fine except one important thing - when I click on "Done" button while in landscape, I see my view controller in landscape too after video player shuts down. – etolstoy Feb 25 '14 at 06:37
  • please let me know you have comment all code except this one related to orientation or not ? if not then pls comment it's working here fine. – Shubham Feb 25 '14 at 06:47
  • Thanks, it finally worked! I've missed one line of code, deleted it - and everything was fine! I'll give you your bounty in 6 hours. – etolstoy Feb 25 '14 at 07:30
  • Thanks I'll wait for this enjoyeeee:) – Shubham Feb 25 '14 at 07:34
1

I was the same problem and now I am telling you how I solved it. I don't know the below method is right or wrong but it work fine.

  • Instead of opening MPMoviePlayer in view open it in a new viewController. I mean create a new UIViewController to show the movie and push it some how so that user will not understood that they are redirecting into a new screen.
  • Disable the parent screen for landscape mode and allow MovieViewController to landscape.
  • When user press the done button or close button simply pop the viewController and as the previous screen don't support landscape mode so the screen will automatically shows in portrait mode.
Tapas Pal
  • 7,073
  • 8
  • 39
  • 86
0
[[NSNotificationCenter defaultCenter] addObserver:self
                                  selector:@selector(_moviePlayerWillExitFullscreen:)
                                         name:MPMoviePlayerWillExitFullscreenNotification object:nil];


- (void)_moviePlayerWillExitFullscreen:(NSNotification *)notification 
{
    CGFloat ios = [[[UIDevice currentDevice] systemVersion] floatValue];
    CGFloat min = 5.0;
    if (ios >= min)
    {
        if (self.interfaceOrientation != UIInterfaceOrientationPortrait)
        {  
            if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
            {
                [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
                [self willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
                [UIViewController attemptRotationToDeviceOrientation];
            } 
        }
    }   
}

Note that this only works in ios 5.0 and later, and you will get a warning that setOrientation is not supported, but it works pretty well

Ramy Kfoury
  • 937
  • 5
  • 8
-1

One way you could try is to force your device to think it is in portrait mode. To do this, try using:

[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];

If you do not want your device to show landscape while not playing a movie, you will also have to add some logic to your code that you have shown above to only change to landscape if the movie is playing.

WolfLink
  • 3,308
  • 2
  • 26
  • 44
  • 2
    Do not use that method, it is undocumented and part of a private API - hence reason for being rejected. – Till Sep 14 '11 at 12:07