我已经将AVPlayerViewController子类化,以便我可以通过覆盖supportedInterfaceOrientations
在iPhone上以横向模式显示它。这很好用。但是当我点击右下角的云选择Subtitle和CC选项时,它将以Portrait模式打开。可能是什么原因?
有没有其他方法可以在横向模式下显示AVPlayerViewController而不进行子类化?
答案 0 :(得分:0)
你的意思是只创建一个简单的类吗?因为很简单,只需创建一个新类并添加一个AVLayer而不是创建一个AVPlayerViewController:
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
AVPlayerItem * playerItem = [AVPlayerItem playerItemWithURL:videoURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:playerLayer];
[player play];
然后覆盖正确的方法:
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}