i自定义AVPlayerViewController
通过创建类LandscapeAVPlayerController
继承类AVPlayerViewController
来处理玩家方向。
然后我使用LandscapeAVPlayerController
播放一些流视频网址,如下所示:
let videoURL = URL(string: tmpStrURL)
let player = AVPlayer(url: videoURL!)
let playerViewController = LandscapeAVPlayerController()
playerViewController.player = player
playerViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen
this.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
LandscapeAVPlayerController类
import AVKit
class LandscapeAVPlayerController: AVPlayerViewController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask
{
return .landscape
}
override var shouldAutorotate: Bool {
return true
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
AppDelegate.AppUtility.lockOrientation(.portrait)
}
}
它可以与旧的ios版本完美配合。但是最近,有几台设备更新到ios 12,并且单击关闭按钮时播放器控制器无法关闭。它仅在ios 12上发生。
我尝试使用AVPlayerViewController
用户,但得到相同的结果。