AVPlayerViewController (tvOS) doesn't pause on viewWillDisappear

只谈情不闲聊 提交于 2020-01-04 05:38:05

问题


I have several AVPlayerViewControllers set as the ViewControllers of a UITabBarController. What I want is having the video of the currently visible AVPlayerViewController automatically pause playing when the user switches to another tab (which is another AVPlayerViewController)

I tried this approach:

override func viewWillDisappear(animated: Bool) {
    player?.pause()

    super.viewWillDisappear(animated)
}

but the video just keeps running in the background. (audio is still running at least) Debugger says player property is not nil in viewWillDisappear. I already tried implicitly and forced unwrapping, to no avail.


回答1:


I was able to identify the problem. It seems to be that you can't pause in viewWillDisappear, neither with pause() nor with player?.rate = 0.0. So in order to prevent your video from playing in the background, you have to set AVPlayerViewController's player property to nil in viewWillDisappear. Which sadly means that you have to write some code for preserving your playback state.

Seems a bit like a bug to me, hope this will get fixed later.



来源:https://stackoverflow.com/questions/33840994/avplayerviewcontroller-tvos-doesnt-pause-on-viewwilldisappear

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