Article

Adopting Picture in Picture in a Standard Player

Add picture-in-picture controls to your player using a player view controller.

Overview

The simplest way to add picture-in-picture playback to your apps is with AVPlayerViewController. In fact, after you’ve configured your audio session and set the project capabilities as described in the AVAudioSession 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.

Standard player with Picture in Picture option highlighted in the bottom right.

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.

Picture in Picture window overlay showing fullscreen, play, and close options.

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 AVPlayerViewControllerDelegate protocol and implement the playerViewController:restoreUserInterfaceForPictureInPictureStopWithCompletionHandler: 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 presentViewController:animated:completion: method of UIViewController, restore your player interface in the same way in the delegate callback method.

func playerViewController(_ playerViewController: AVPlayerViewController,
                          restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: (Bool) -> Void) {
    present(playerViewController, animated: true) {
        completionHandler(false)
    }
}

See Also

Media Playback

Adopting Picture in Picture in a Custom Player

Add picture-in-picture controls to your custom player using a picture-in-picture controller.

Working with Interstitial Content (tvOS)

Present additional content such as legal text, content warnings, or advertisements alongside your main media content.

Adding Information to the Info Panel (tvOS)

Add metadata information and navigation markers to the Info panel in Apple TV.

Adopting Custom Interactive Overlays, Channel Flipping, and Parental Controls in tvOS Video Playback

This sample demonstrates support for custom interactive overlays, and parental controls, using AVPlayerViewController.

AVPlayerViewController

An object that displays the video content from a player object along with system-supplied playback controls.

AVPlayerView

A macOS-only object that displays the video content from a player object along with system-supplied playback controls.

AVPictureInPictureController

A controller that responds to user-initiated playback of video in a floating, resizable window on iPad.

AVRoutePickerView

An object that displays controls for picking playback routes.

AVInterstitialTimeRange

A time range in an audiovisual presentation as interstitial content, such as advertisements or legal notices.

AVNavigationMarkersGroup

A set of markers for navigating playback of an audiovisual presentation.