Add Picture in Picture (PiP) playback to your app using a player view controller.
The simplest way to add PiP playback to your apps is with
AVPlayer. In fact, after you’ve configured your audio session and set the project capabilities as described in Configuring iOS and tvOS Audio Playback Behavior, your player automatically supports PiP playback. If your app is running on a supported device, you’ll see a new button in the lower-right corner of your player.
Familiarize Yourself with the Picture in Picture Controls
Picture in Picture playback starts when the user taps the PiP button in the player interface. Playback also starts automatically if your video is playing in full-screen mode and you exit the app by pressing the Home button. In either case, the player window is minimized to a movable, floating window.
While the video is playing in PiP mode, the user has basic controls to play and pause the video as well as exit playback. Tapping the leftmost button in this interface exits Picture in Picture and returns control to your app, but by default immediately terminates video playback. AVKit can’t make assumptions about how your app is designed and is unaware of how to properly restore your video playback interface. Instead, it delegates that responsibility to you.
Restore Your Video Playback Interface
To handle the restore process, your code must adopt the
AVPlayer protocol and implement the
player method. The framework calls this method when control returns to your app, giving you the opportunity to determine how to properly restore your video player’s interface. If you originally presented your video player using the
present method of
UIView, restore your player interface in the same way in the delegate callback method.