我正在使用AVPlayerViewController播放视频,该视频在iOS 11上可以正常使用,但相同的代码在iOS 12中不起作用。有人可以帮我解决此问题吗?

 let url: URL = Bundle.main.url(forResource: "sampleVideo", withExtension: ".mp4")!

    let avAsset = AVURLAsset(url: url)
    let playerItem = AVPlayerItem(asset: avAsset)
    player = AVPlayer(playerItem: playerItem)
    playerController = AVPlayerViewController()
    playerController?.player = player
    playerController?.view.frame = videoHolderView?.bounds ?? CGRect.zero

    guard let videoView = playerController?.view else { return }
    videoView.tag = 101
    videoHolderView.addSubview(videoView)
    player?.play()

最佳答案

终于找到了问题!!!
在iOS 12中,如果禁用AVPlayerController的 PlayBackControls ,则AVPlayer仍将使用轻击手势。
playerController?.showsPlaybackControls = false

10-08 05:30