在iOS 11上滑动时AVPlayerViewController黑屏 [英] AVPlayerViewController black screen when swiping on iOS 11

查看:59
本文介绍了在iOS 11上滑动时AVPlayerViewController黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AVPlayerViewController 在iPad-App上播放视频文件(H.264,AAC,MP4-容器).一切都可以在iOS 10中正常工作.在iOS 11中,它也可以正确播放视频.

I'm using AVPlayerViewController to play a video file (H.264, AAC, MP4-Container) on an iPad-App. Everything is working in iOS 10. And also in iOS 11 it plays the video correctly.

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

But in iOS 11, when I start swiping in any direction, it immediately blacks out the video and also mutes audio. It also shows a loading indicator next to the timeline on the bottom.

此外,它还会忽略 allowsPictureInPicturePlayback 属性,因此它不会在iOS 11上显示PIP按钮.

Also it ignores the allowsPictureInPicturePlayback property, so it doesn't show the PIP-Button on iOS 11.

这是我使用的代码:

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)

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

And this function to close the Video Player at the end of the video:

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

当屏幕黑屏时,我会在控制台中看到此消息:

When the screen blacks out I get this in the Console:

AVOutputDeviceDiscoverySession (FigRouteDiscoverer) 
>>>> -[AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl 
outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device discovery 
mode to DiscoveryMode_Presence (client: MyAppName)

推荐答案

好的,我发现了错误:要在按下完成"时关闭Airplay视频播放,我使用了以下代码:

Okay I found the mistake: To close the Airplay video playback when pressing "Done" I used this code:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

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

但是在iOS 11上,苹果增加了一项功能,可通过滑动手势关闭视频播放器.因此,当我滑动时,会调用 viewWillAppear 函数.将此代码放入 viewDidAppear 中即可解决此问题,并保留了AirPlay-Fix.

But with iOS 11, Apple added a feature to close the Video Player via a swipe gesture. So when I swipe, the viewWillAppear function gets called. Putting this code inside viewDidAppear fixed this and preserved the AirPlay-Fix.

这篇关于在iOS 11上滑动时AVPlayerViewController黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆