In my iOS Video Player, when in the Picture-in-Picture mode (PIP), how can I handle specific user actions like close
or restore
. The existing delegate provides a way to know when PIP mode is stopped but I wan't different behavior to be executed on different user actions:
- close - let the controller go and keep it closed
- restore - re-present the player and continue playback
After implementing AVPlayerViewControllerDelegate
, AVPlayerViewController calls the following functions regardless of what button user tapped:
playerViewControllerWillStopPictureInPicture
playerViewControllerDidStopPictureInPicture
I also defined method restoreUserInterfaceForPictureInPictureStopWithCompletionHandler
but it seems not getting called for some reason on exit from the PIP mode.
func restoreUserInterfaceForFullScreenExit(completionHandler: @escaping (Bool) -> Void) {
completionHandler(true)
}
func restoreUserInterfaceForPictureInPictureStop(completionHandler: @escaping (Bool) -> Void) {
completionHandler(true)
}
In general I have view that contained AVPLayer
playerView
and it has delegate:I've implemented required methods by the following way and it works for me:
May be your delegate bacomes nil at some place of code?