iOS Get the instance of the current Picture-in-Picture player

539 views Asked by At

I have a custom controller which contains a YTPlayerView and is showed to the navigation stack when user clicks on a video. It was all good, until there was Picture-in-Picture on iPads.

I figured that when the user makes the player to play PiP, clicking on the back button(popping this player controller from the navigation stack) will not destroy the player instance, as the PiP will pause, and it continues to play when the user clicks the play button.

This causes a problem: when a PiP is running, and the user clicks on another video, then a new instance of this controller is generated from storyboard via instantiateViewController(withIdentifier:), and is showed, the app crashed with the following message:

'Application tried to present modally an active controller <UINavigationController: 0x7fe862ef82d0>.' (I am certain that I called show not present)

What I want to do is to grab the current PiP instance (if there is one), and to stop it before showing the newer controller. How can I achieve that? (As I don't want to disable PiP)

0

There are 0 answers