Class

AVPictureInPictureController

An AVPictureInPictureController lets you respond to user-initiated playback of video in a floating, resizable window on iPad.

Overview

When you use this class, your app is responsible for providing a button for the user to tap to invoke the Picture in Picture feature with your content. Before displaying the button, call the isPictureInPictureSupported() method to determine if the user’s iPad supports the feature, and check the isPictureInPicturePossible property to determine whether PiP is possible in the current context.

To participate with Picture in Picture, take the following steps in your Xcode project:

  1. Link on or after iOS 9.0.

  2. In the Xcode Capabilities view for your project, select Audio and AirPlay in the Background Modes section.

  3. Configure your audio session with an appropriate category, such as AVAudioSessionCategoryPlayback.

Symbols

Creating and Configuring a Picture in Picture Controller

init?(playerLayer: AVPlayerLayer)

The designated initializer for a Picture in Picture controller.

var delegate: AVPictureInPictureControllerDelegate?

The delegate object for the Picture in Picture controller.

var playerLayer: AVPlayerLayer

The AVPlayerLayer instance containing the media to play.

Accessing Picture in Picture State

class func isPictureInPictureSupported()

Indicates whether Picture in Picture is supported on the current device.

var isPictureInPicturePossible: Bool

Indicates whether the Picture in Picture playback is currently possible.

var isPictureInPictureActive: Bool

Indicates whether the controller’s Picture in Picture window is onscreen.

var isPictureInPictureSuspended: Bool

Indicates whether the controller’s Picture in Picture window is suspended.

Controlling Picture in Picture Playback

func startPictureInPicture()

Starts Picture in Picture for the associated AVPlayerLayer instance, if possible.

func stopPictureInPicture()

Stops Picture in Picture for the associated AVPlayerLayer instance, if it is currently active.

Retrieving Picture in Picture Template Images

You can use the following methods to retrieve system default images to start and stop Picture in Picture playback in your custom player interface. The images returned match the ones found in the user interface provided by AVPlayerViewController.

class func pictureInPictureButtonStartImage(compatibleWith: UITraitCollection?)

Returns the system default Picture in Picture start template image for use in your player’s Picture in Picture button.

class func pictureInPictureButtonStopImage(compatibleWith: UITraitCollection?)

Returns the system default Picture in Picture stop template image for use in your player’s Picture in Picture button.

Relationships

Inherits From

Conforms To