Enable Picture-in-Picture for Native and Custom AVPlayers (iOS)
Native Video Players
Take the following steps to enable Picture-in-Picture for native AVPlayers:
-
Go to your application project’s Signing & Capabilities view.
-
If you don’t already have Background Modes available, click the + button to add that section.
-
Under Background Modes, add a checkmark to Audio, Airplay, and Picture in Picture.
-
Call the following function to enable a background session:
PictureInPictureManager.activatePictureInPictureSession()
The function starts a Picture-in-Picture session when backgrounding your application.
Custom Players
After completing the steps for native AVPlayers, take the following additional steps:
-
Locate where your custom player is being managed.
-
Call
PictureInPictureManager
’s setup function. -
Provide the associated
AVPlayer
andUIViewController
instances:PictureInPictureManager.setUp(with: AVPlayer, for: viewController)
Now you must be able to dismiss the application and see your video player enter Picture-in-Picture mode the same way it does for the native player.