Reputation: 571
I have PIP working using AVPlayer, AVPlayerViewController
By default, when entering back into the app/view from background with PIP active, I'd like it to return back into the view.
My issue is that when I setup the AVPictureInPictureController using my AVPlayerLayer, I can get back pip observations however, none of the pipController methods like stopPictureInPicture() or isPictureInPictureActive work or return false.
How can I get both AVPlayerViewController and AVPictureInPictureController to work together?
if AVPictureInPictureController.isPictureInPictureSupported() { // Create a new controller, passing the reference to the AVPlayerLayer.
DispatchQueue.main.async {
videoController.pipController = AVPictureInPictureController(playerLayer: videoController.playerLayer)
videoController.pipController!.delegate = videoController
videoController.pipPossibleObservation = videoController.pipController!.observe(\AVPictureInPictureController.isPictureInPicturePossible,
options: [.initial, .new]) { _, change in
// Update the PiP button's enabled state.
print("Can pip")
DispatchQueue.main.asyncAfter(deadline: .now() + 10.0) {
print("Stop Pip")
print("\(videoController.pipController!.isPictureInPictureActive)") // Returns false
}
}
}
} else {
// PiP isn't supported by the current device. Disable the PiP button.
print("Can not pip")
}
Upvotes: 1
Views: 606