JonEasy
JonEasy

Reputation: 1013

AVPlayerViewController (tvOS) doesn't pause on viewWillDisappear

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.

Upvotes: 2

Views: 1900

Answers (1)

JonEasy
JonEasy

Reputation: 1013

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.

Upvotes: 2

Related Questions