0

I have my app in portrait mode.

When video player enters full screen mode, I want to play that video in both landscape and portrait orientation.

moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayer.view setAutoresizingMask:(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth)];

[moviePlayer setScalingMode:MPMovieScalingModeFill];

moviePlayer.view.frame = CGRectMake(0, 0, self.videoPlayerView.frame.size.width, self.videoPlayerView.frame.size.height);
[self.videoPlayerView addSubview:moviePlayer.view];

and I am playing it on one button.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Aditya
  • 333
  • 3
  • 9

3 Answers3

0
For you question i would like to give the below Reference

Portrait video to landscape and

Allow video on landscape with only-portrait app

Community
  • 1
  • 1
user3182143
  • 9,459
  • 3
  • 32
  • 39
0

Enable your Landscape Device Orientation in Deployment Info. Then, add these methods in your ViewController:

- (BOOL) shouldAutorotate {
    return NO;
}

- (NSUInteger) supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation) preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}
Pepeng Hapon
  • 357
  • 1
  • 17
0

Try to add a canvas view as superview to your player and apply transformation to the canvas view.

- (void)initialize{    
    self.canvas = [[UIView alloc] initWithFrame: self.view.bounds];
    [self.view addSubview:self.canvas];

    // init moviePlayer
    moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
    ...
    [self.canvas addSubview: moviePlayer.view];

    // Add observers
    ...
    [[NSNotificationCenter defaultCenter] addObserver: self
                     selector: @selector(deviceOrientationDidChange)
                         name: UIDeviceOrientationDidChangeNotification
                       object: nil];
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}

- (void)deviceOrientationDidChange{
    // Apply rotation only in full screen mode
    if (self.isFullScreen) {
        UIDeviceOrientation currentOrientation = [UIDevice currentDevice].orientation;

        [UIView animateWithDuration: 0.3 
                         animations: ^{
             CGAffineTransform transform = CGAffineTransformMakeRotation(0);
             switch (orientation) {
                 case UIDeviceOrientationLandscapeLeft:
                     transform = CGAffineTransformMakeRotation(M_PI_2);
                 break;
                 case UIDeviceOrientationLandscapeRight:
                     transform = CGAffineTransformMakeRotation(M_PI + M_PI_2);
                 break;
                 default:
                 break;
            };

            self.canvas.transform = transform;
            self.canvas.frame = self.canvas.superview.bounds;
        }];
    }
}
user3687611
  • 31
  • 1
  • 4