iOS SDK Picture-In-Picture

Enable Picture-In-Picture mode

If you want to use Picture-In-Picture in your app you can instantiate the player with a THEOplayerConfiguration object that enables the Picture-In-Picture mode.

let playerConfig = THEOplayerConfiguration(pictureInPicture: true)
var theoplayer = THEOplayer(configuration: playerConfig)

Once the Picture-In-Picture mode is enabled, the player's pip property can be accessed.

Configure the Picture-In-Picture mode

Using the configure(movable:defaultCorner:) method of the player's pip property you can configure the picture-in-picture (PiP)

You can configure:

  • whether the PiP view is movable or not (default to true);
  • the default corner of the PiP view (default to bottom right);
theoplayer.pip!.configure(movable: false, defaultCorner: .bottomLeft)

Observe when the Picture-In-Picture moves

Using the notification center you can listen to the PictureInPictureMoved notification. This notification will be pushed every time the picture-in-picture view moves to a different corner.

In the callback, you can retrieve the previous and the new corner in the userInfo dictionary respectively with the PictureInPictureOldCornerUserInfoKey and the PictureInPictureNewCornerUserInfoKey keys.

NotificationCenter.default.addObserver(self, selector: #selector(onPiPMoved), name: Notification.Name.PictureInPictureMoved, object: nil)

@objc func onPiPMoved(notif: Notification) {
    let userInfo = notif.userInfo as! [String: Any]
    let oldCorner : PictureInPictureCorner = userInfo[PictureInPictureOldCornerUserInfoKey]! as! PictureInPictureCorner
    let newCorner : PictureInPictureCorner = userInfo[PictureInPictureNewCornerUserInfoKey]! as! PictureInPictureCorner
    print("PiP has moved from \(oldCorner) to \(newCorner)")
}