Is iOS PIP (Picture In Picture) for Video Call a private API?

Viewed 4350

I noticed that none of the video calling apps except Facetime allows you to do a video call/chat when in background through PIP.

How did Facetime achieve it? Is it a private API that we can’t use?

I have tried to search blogs, forums, StackOverflow, the official documentation, but I haven't seen a definitive answer.

I'm skeptical because this official doc mentions the following, but it didn't specify PIP there:

Camera usage is prohibited while in the background. If you attempt to start running a camera while in the background, the capture session sends an AVCaptureSessionWasInterruptedNotification with this interruption reason. If you don't explicitly call the stopRunning method, your startRunning request is preserved, and when your app comes back to foreground, you receive AVCaptureSessionInterruptionEndedNotification and your session starts running.

2 Answers

(See update below)

OLD

Yes, it is achieved through private APIs. It is not possible for third-party apps to do this.

Basically people have played around with live-streaming video with low latency and displaying that in PiP mode. It is not easy to do right, but it is doable. However, you cannot keep the camera active during PiP, so a video call is unfortunately still not possible (at least it would be one-sided).

UPDATE:

With iOS 15 it is now possible using the "Multitasking Camera Access Entitlement" to keep the camera recording while in PiP mode using the AVPictureInPictureController.

iOS 15 Update;

Adopting Picture in Picture for Video Calls

Create a Source View

class SampleBufferVideoCallView: UIView {
    override class var layerClass: AnyClass {
        get { return AVSampleBufferDisplayLayer.self }
    }

    var sampleBufferDisplayLayer: AVSampleBufferDisplayLayer {
        return layer as! AVSampleBufferDisplayLayer
    }
}

Create a Video-Call Controller

let pipVideoCallViewController = AVPictureInPictureVideoCallViewController()
pipVideoCallViewController.preferredContentSize = CGSize(width: 1080, height: 1920)
pipVideoCallViewController.view.addSubview(sampleBufferVideoCallView)

Create a PiP Controller using a Content Source

let pipContentSource = AVPictureInPictureController.ContentSource(
                            activeVideoCallSourceView: videoCallViewSourceView, 
                            contentViewController: pipVideoCallViewController)


let pipController = AVPictureInPictureController(contentSource: pipContentSource)
pipController.canStartPictureInPictureAutomaticallyFromInline = true
pipController.delegate = self

Observe Picture in Picture Lifecycle Events

When you use PiP, you respond to life-cycle events by observing AVPictureInPictureControllerDelegate. This allows you to handle your app’s user interface based on the PiP state, along with observing for potential errors.

Related