How to handle AVPlayer when device changes orientation?

898 views Asked by At

My app only supports portrait orientation. But I have used AVPlayerViewController in one screen. App has UINavigationViewController and UITabBarViewController. When device is rotated to landscape mode during video play, I am having hard time to change its frame?

How can I achieve this? Where should I change frame of AVPlayerView?

1

There are 1 answers

2
TheHungryCub On
NSNumber *val = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:val forKey:@"orientation"];

Or ask the visible View Controller :

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return self.CurrentViewController.preferredInterfaceOrientationForPresentation;
}

- (BOOL)shouldAutorotate {
    return self.CurrentViewController.shouldAutorotate;
}