仅 iPhone x 的 AVPlayer 全屏问题

AVPlayer full screen issue only for iPhone x

我使用 Av 播放器视图控制器创建了启动视频。它适用于除我 Phone X 以外的所有设备。我尝试更改视频重力框架和所有内容,但它不起作用。对此有什么想法吗?这是示例代码:

guard let videoPath = Bundle.main.path(forResource: "Redtaxi-splash", ofType:"mov") else {
    return
}

let videoURL = URL(fileURLWithPath: videoPath)
let player = AVPlayer(url: videoURL)
playerViewController = AVPlayerViewController()
playerViewController?.player = player
playerViewController?.showsPlaybackControls = false
playerViewController?.view.frame = view.frame
playerViewController?.view.backgroundColor = .white
playerViewController?.view.contentMode = .scaleAspectFill


NotificationCenter.default.addObserver(self, selector: #selector(playerDidFinishPlaying(note:)),
                                       name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: player.currentItem)

view.addSubview((playerViewController?.view)!)
playerViewController?.player?.play()

我通过为播放器视图控制器赋予视频引力来修复此问题:

playerViewController.videoGravity = .resizeAspectFill

这将通过使用视频引力作为 avplayer 视图控制器的纵横比填充来解决此问题。这是视频重力的文档:

The video gravity determines how the video content is scaled or stretched within the player layer’s bounds.

Swift 4

playerViewController.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue