热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在iOS11上滑动时AVPlayerViewController黑屏

如何解决《在iOS11上滑动时AVPlayerViewController黑屏》经验,为你挑选了1个好方法。

我正在AVPlayerViewControlleriPad-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)

fl034.. 6

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

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

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

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



1> fl034..:

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

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

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

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


推荐阅读
author-avatar
琳琳小朋友m
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有