swift – 在iOS 11上滑动时AVPlayerViewController黑屏

我正在使用AVPlayerViewController在iPad-App上播放视频文件(H.264,AAC,MP4-Container).
一切都在iOS 10中运行.而且在iOS 11中它正确播放视频.

但是在iOS 11中,当我开始向任何方向滑动时,它会立即使视频变黑并且还会使音频静音.它还会在底部的时间轴旁边显示一个加载指示器.

它也忽略了allowsPictureInPicturePlayback属性,因此它不会在iOS 11上显示PIP-Button.

这是我使用的代码

avPlayerController = AVPlayerViewController()
avPlayerController?.showsPlaybackControls = true
avPlayerController?.allowsPictureInPicturePlayback = true
avPlayerController?.player = AVPlayer(url: videoUrl as URL)
avPlayerController?.player?.play()            

self.present(self.avPlayerController!,animated: true,completion: nil)            

avPlayerController?.player?.actionAtItemEnd = AVPlayerActionAtItemEnd.none
NotificationCenter.default.addobserver(self,selector: #selector(onVideoCompleted),name: NSNotification.Name.AVPlayerItemDidplayToEndTime,object: self.avPlayerController!.player?.currentItem)

功能可在视频结束时关闭视频播放器:

func onVideoCompleted(notification:Notification) {
    self.avPlayerController?.player = nil
    self.avPlayerController?.dismiss(animated: true,completion: nil)
}

当屏幕黑屏时,我在控制台中看到了这个:

AVOutputDevicediscoverySession (figRoutediscoverer) 
>>>> -[AVfigRoutediscovererOutputDevicediscoverySessionImpl 
outputDevicediscoverySessionDidChangediscoveryMode:]: Setting device discovery 
mode to discoveryMode_Presence (client: MyAppName)
好的,我发现了错误
要在按“完成”时关闭Airplay视频播放,我使用了以下代码
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    if avPlayerController?.isBeingdismissed ?? false {
        avPlayerController?.player = nil
    }
}

但是对于iOS 11,Apple添加了一项功能,通过轻扫手势关闭视频播放器.因此,当我滑动时,会调用viewWillAppear函数.将此代码放在viewDidAppear中修复此问题并保留AirPlay-Fix.

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...