AVPlayerViewController black screen when swiping on iOS 11

你。 提交于 2019-12-22 05:05:32

问题


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.

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.

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

This is the code I use:

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)

回答1:


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
    }
}

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.



来源:https://stackoverflow.com/questions/46321860/avplayerviewcontroller-black-screen-when-swiping-on-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!