Add picture-in-picture controls to your player using a player view controller.
The simplest way to add picture-in-picture playback to your apps is with
AVPlayer. In fact, after you’ve configured your audio session and set the project capabilities as described in the
AVAudio overview, your player automatically supports picture-in-picture playback. If your app is running on a supported iPad 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 picture-in-picture 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 picture-in-picture mode, the user has basic controls to play and pause the video as well as exit picture-in-picture 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 structured 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. This method is called 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.