0

My application includes a video to be viewed in landscape mode, I applied the following code:

- (IBAction)videoAction:(id)sender {

    NSString *path = [[NSBundle mainBundle] pathForResource:@"MTLowRes" ofType:@"mp4"];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
    [self presentModalViewController:moviePlayer animated:NO];
}

Code for managing landscape orientation in AppDelegate.m is as follows:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)windowx
    {
        if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
            [[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])
        {
            if ([self.window.rootViewController presentedViewController].isBeingDismissed)
            {
                return UIInterfaceOrientationMaskPortrait;
            }
            else
            {
                return UIInterfaceOrientationMaskAllButUpsideDown;
            }
        }
        else
        {
            return UIInterfaceOrientationMaskPortrait;
        }
    }

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    if ([[self.window.rootViewController presentedViewController] isKindOfClass:[MPMoviePlayerViewController class]] ||
        [[self.window.rootViewController presentedViewController] isKindOfClass:NSClassFromString(@"MPInlineVideoFullscreenViewController")])
    {
       return UIInterfaceOrientationLandscapeLeft;
    }
    else
    {
        return UIInterfaceOrientationPortrait;
    }
}

This works fine, but the video is not rotating to full screen when I select the option to view full screen.

I tried applying the same code on another View Controller, where video works fine in landscape full screen mode.The only issue is with the current view controller.

Braiam
  • 1
  • 11
  • 47
  • 78
  • which iOS version you are using? For iOS <=6 use "shouldAutorotate". Above iOS6 please implement preferredInterfaceOrientationForPresentation and supportedInterfaceOrientations. If you are working on iOS 9, then MPMoviePlayerViewController has been deprecated. – Gagan_iOS Nov 02 '15 at 12:59
  • @Gagan_iOS please check the update code , I have used preferredInterfaceOrientationForPresentation , still video does not work in landscape full screen orientation. Also , I am working on iOS 9,and heard of using AVPlayerViewController for iOS 9,kindly suggest if there is a better option. – DeveloperIOS Nov 02 '15 at 13:24
  • As you told you are working on iOS 9, I would suggest to use AVPlayerViewController with AVKit. IMPORTANT The MPMoviePlayerViewController class is formally deprecated in iOS 9. (The MPMoviePlayerController class is also formally deprecated.) To play video content in iOS 9 and later, instead use the AVPictureInPictureController or AVPlayerViewController class from the AVKit framework, or the WKWebView class from WebKit. Please look into this : http://stackoverflow.com/questions/25932570/how-to-play-video-with-avplayerviewcontroller-avkit-in-swift – Gagan_iOS Nov 03 '15 at 06:00
  • @Gagan_iOS , I tried using AVPlayerViewController but still not able to view video in landscape mode,any other suggestion please..? – DeveloperIOS Nov 03 '15 at 10:01

0 Answers0