0

According to the documentation, the willStop and didStop delegate methods, along with restoreUserInterfaceForPictureInPictureStopWithCompletionHandler get called when the AVPictureInPictureController closes, regardless of how it is closed. How do I tell if the controller is being closed by the "X" button or the other button to return to regular playback?

cable_pair
  • 93
  • 6

1 Answers1

3

The different between the X button and restore button is :

Tapping on restore PiP button will trigger

"pictureInPictureController(_:restoreUserInterfaceForPictureInPictureStopWithCompl etionHandler:)"
"pictureInPictureControllerWillStopPictureInPicture"
"pictureInPictureControllerDidStopPictureInPicture"

While tapping on close button will skipping the restoreUserInterface callback and go straight to

"pictureInPictureControllerWillStopPictureInPicture"
"pictureInPictureControllerDidStopPictureInPicture"

So you can using a Bool flag to check in willStop/DidStop whether it has called restoreUserInterface or not.

There is also a pictureInPictureSuspended property in AVPictureInPictureViewController but i tried checking it value and found out it always return false in both case so i have to use above trick to check whether user tapped on restore or close button.

untouchable
  • 206
  • 1
  • 11