4

I am using autolayout and in a screen I create AVPlayerViewController with half the size of main view. I am using UITabBarViewController and UINavigationController. This screen is navigated from first child ViewController of UITabBarViewController. Code is like this..

    avPlayerVideoController = [[AVPlayerViewController alloc] init];

    avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:videoURL]];

    avPlayerVideoController.view.frame = CGRectMake( imgViewVideo.frame.origin.x, imgViewVideo.frame.origin.y, imgViewVideo.frame.size.width, imgViewVideo.frame.size.height);
    avPlayerVideoController.delegate = self;
    avPlayerVideoController.showsPlaybackControls = YES;
    avPlayerVideoController.player = avPlayer;
    [avPlayerVideoController.player play];

now I want the video to be rotated in landscape view when I click on that full screen button comes with AVPlayerViewController. It just remains in portrait orientation even I rotate my phone. And there is also no delegate method called when full screen button is tapped. Please I need this badly. Explain in detail how I should achieve this. Thank you

Hiren Prajapati
  • 717
  • 3
  • 10
  • 25

2 Answers2

2

add below code to your viewController with contains AVPlayerViewController

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

Hope it Helps you.

Vvk
  • 4,031
  • 29
  • 51
  • It didn't help me. When this method supportedInterfaceOrientations called? And I have used TabBarViewController. And this is the not the most top ViewController. It is navigated from the top lever ViewController. – Hiren Prajapati Apr 05 '16 at 05:18
  • @HirenPrajapati your `AVPlayerViewController ` is added subview or presented? – Vvk Apr 05 '16 at 05:26
  • oh my bad. In my project I only enabled portrait view. Btw AVPlayerViewController is added as subview. After enabling landscaped orientation from project, now I only want to change orientation when user clicks full screen button. How can I do this? Am I doing wrong? Just because of one screen should I turn on landscape orientation support? Because screen rotates in every ViewController. – Hiren Prajapati Apr 05 '16 at 05:33
  • So after understanding issue completely, now my question is by disabling landscape orientation support from project, how this added AVPlayerViewController in self.view can rotate to landscape when tapping full screen button? – Hiren Prajapati Apr 05 '16 at 05:40
  • yes this is right way to disabling landscape from project. but i can'w understand why are you adding AVPlayer as subview? why are you not presentining? can you please temm me for better understaing your issue – Vvk Apr 05 '16 at 06:00
1
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    [avPlayerLayer removeFromSuperlayer];
    [avPlayerLayer setFrame:self.view.bounds];
    [self.view.layer addSublayer:avPlayerLayer];
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
Frits
  • 7,341
  • 10
  • 42
  • 60
tju077
  • 11
  • 1