用于视频呼叫的iOS PIP(画中画)是一个私有的API吗



我注意到,除了Facetime之外,没有任何视频通话应用程序允许您在后台通过PIP进行视频通话/聊天。

Facetime是如何实现的?它是我们不能使用的私有API吗?

我试过搜索博客、论坛、StackOverflow、官方文档,但还没有找到确切的答案。

我对此持怀疑态度,因为这份官方文件提到了以下内容,但没有具体说明PIP:

在后台时禁止使用相机。如果您试图在后台开始运行相机,则捕获会话会发送一个AVCaptureSessionWasInterruptedNotification,其中包含此中断原因。如果你没有显式调用stopRunning方法,你的startRunning请求将被保留,当你的应用程序返回前台时,你会收到AVCaptureSessionInterruptionEndedNotification,你的会话将开始运行。

(请参阅下面的更新(

旧的

是的,它是通过私有API实现的。第三方应用程序不可能做到这一点。

基本上,人们已经玩过低延迟的直播视频,并在PiP模式下显示。做正确的事情并不容易,但它是可行的。然而,在PiP期间,您无法保持相机处于活动状态,因此不幸的是,视频通话仍然不可能(至少是单方面的(。

更新:

对于iOS 15,现在可以使用";多任务摄像机访问权限";使用AVPictureInPictureController在PiP模式下保持相机记录。

iOS 15更新;

采用画中画进行视频通话

创建源代码视图

class SampleBufferVideoCallView: UIView {
override class var layerClass: AnyClass {
get { return AVSampleBufferDisplayLayer.self }
}
var sampleBufferDisplayLayer: AVSampleBufferDisplayLayer {
return layer as! AVSampleBufferDisplayLayer
}
}

创建视频呼叫控制器

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

使用内容源创建PiP控制器

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

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

观察画中画生命周期事件

使用PiP时,通过观察AVPictureInPictureControllerDelegate来响应生命周期事件。这允许您根据PiP状态处理应用程序的用户界面,同时观察潜在的错误。

最新更新