Search code examples
iosios8mpmovieplayercontrollermpmovieplayerxcode6.1

MPInlineVideoFullscreenViewController and AVFullScreenViewController first time comes in portrait mode


There are too many questions related to landscape issue in MPMovieplayer. My application is in portrait mode.But i wanna video in landscape mode.I already have landscape/portrait functionality for video. I am using the following code:

static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
    [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
{

    return UIInterfaceOrientationMaskAllButUpsideDown;
}
else {
    return UIInterfaceOrientationMaskPortrait;
}

}

The Code is working fine in both iOS 7 and iOS8. But the problem is that video first open in portrait mode while device is in landscape mode.After a change in orientation than app works fine.

Thanks in advance.


Solution

  • After long R&D and different-different approaches and spending 2-3 days.Finally i got an answer with the help of my friend.If our view controller is in portrait mode than the following code is not able to push player view in landscape view.

    static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS7 = @"MPInlineVideoFullscreenViewController";
    static NSString * const VIDEO_CONTROLLER_CLASS_NAME_IOS8 = @"AVFullScreenViewController";
    
    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
      if ([[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS7)] ||
    [[window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(VIDEO_CONTROLLER_CLASS_NAME_IOS8)]) 
    {
      return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else {
    return UIInterfaceOrientationMaskPortrait;
    

    }

    In my case problem is that my UIWebView container view Controller very time comes in portrait mode.I do not know after push ViewController in the UINavigationController following orientation methods not called for that ViewController.

    -(BOOL)shouldAutorotate;  
    -(NSUInteger)supportedInterfaceOrientations;
    

    To solve this issue i will add the following code in the ViewDidLoad method

    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    

    And in following code in viewWillDisappear

    NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
    [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    

    The above code finally solve my issue.

    Thanks to all who was support me to solve this issue.