gpt4 book ai didi

ios - 子类化后的AVPlayerViewController横向定位

转载 作者:行者123 更新时间:2023-12-01 16:31:56 24 4
gpt4 key购买 nike

我将AVPlayerViewController子类化,以便可以通过重写supportedInterfaceOrientations在iPhone上以横向模式显示它。这很好。但是,当我单击右下角的云以选择“字幕”和“抄送”选项时,它将以“人像”模式打开。可能是什么原因?

还有其他方法可以在不子类化的情况下以横向模式显示AVPlayerViewController吗?

最佳答案

您是说只创建一个简单的类吗?因为很简单,所以只需创建一个新的Class并添加一个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;
}

关于ios - 子类化后的AVPlayerViewController横向定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31195065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com