How to rotate the screen in landscape orientation using AVPlayerViewController?

I use autorun, and on the screen I create an AVPlayerViewController with half the size of the main view. I use UITabBarViewController and UINavigationController. This screen moves from the first child ViewController to the UITabBarViewController. The code is as follows.

    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 mode when I click on this full-screen button with AVPlayerViewController. He just stays in portrait orientation, even I rotate my phone. And also there is no delegate method when clicking on the full screen button. Please, I need this badly. Explain in detail how I should achieve this. thank you

+4
2

viewController AVPlayerViewController

-(BOOL)shouldAutorotate{
    return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

, .

+2
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    [avPlayerLayer removeFromSuperlayer];
    [avPlayerLayer setFrame:self.view.bounds];
    [self.view.layer addSublayer:avPlayerLayer];
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
+1

All Articles