AVCaptureDevice.DeviceType
AVCaptureDeviceInput
负责将AVCaptureDevice 转换为输入流,方便captureSession捕捉
AVCapturePreviewLayer
控制的是 AVCaptureVideoPreviewLayer 如何呈现捕捉到的视频内容
AVLayerVideoGravity
resizeAspect
保持视频的原始纵横比,并根据预览层的尺寸进行缩放,确保视频完整地显示在视图中,但可能会出现黑边。
resizeAspectFill
按比例缩放视频内容,以确保填满整个预览层的尺寸,但这可能会导致部分视频内容超出视图的边界(被裁剪掉)。也就是说,它保持视频的纵横比,但会放大视频以完全覆盖预览层。
可以保证没有黑边
resize
忽略视频的纵横比,直接拉伸视频以适应预览层的尺寸。
multiTaskCamera
apple官方文档
如何使用multiTasking
其他人的方案
stackOverFlow相关问题
key code
let captureSession = AVCaptureSession()
// Configure the capture session.
captureSession.beginConfiguration()
if captureSession.isMultitaskingCameraAccessSupported {
// Enable use of the camera in multitasking modes.
captureSession.isMultitaskingCameraAccessEnabled = true //key code
}
captureSession.commitConfiguration()
// Start the capture session.
captureSession.startRunning()
key reason
When you enable multitasking camera access, your app can run alongside other foreground apps and it no longer receives AVCaptureSession.InterruptionReason.videoDeviceNotAvailableWithMultipleForegroundApps as an interruption reason.
也就是一旦设置captureSession.isMultitaskingCameraAccessEnabled = true,app就不会再受到videoDeviceNotAvailableWithMultipleForegroundApps。如果不设置我们就可以通过
NotificationCenter.default.addObserver(self, selector: #selector(sessionWasInterrupted(_:)), name: .AVCaptureSessionWasInterrupted, object: fontCaptureSession)
NotificationCenter.default.addObserver(self, selector: #selector(sessionInterruptionEnded(_:)), name: .AVCaptureSessionInterruptionEnded, object: fontCaptureSession)
@objc func sessionWasInterrupted(_ notification: Notification) {
print("看这里:\(#function),\(notification.userInfo == nil ? "notification.userInfo is empty" :"notification.userInfo is not empty") ")
if let userInfo = notification.userInfo,
let reason = AVCaptureSession.InterruptionReason(rawValue: userInfo[AVCaptureSessionInterruptionReasonKey] as? Int ?? 0) {
print("看这里:\(#function),Session was interrupted. Reason: \(reason)")
switch reason {
case .audioDeviceInUseByAnotherClient:
print("看这里:\(#function),reason:Audio device is in use by another client.")
case .videoDeviceInUseByAnotherClient:
print("看这里:\(#function),reason:Video device is in use by another client.")
case .videoDeviceNotAvailableWithMultipleForegroundApps:
print("看这里:\(#function),reason:Video device is not available because there are multiple foreground apps.")
// if !fontCaptureSession.isRunning {
fontCaptureSession.startRunning()
print("看这里:\(#function),重新开启frontCaptureSession")
// }
case .videoDeviceNotAvailableDueToSystemPressure:
print("看这里:\(#function),reason:Video device is not available due to system pressure.")
@unknown default:
print("看这里:\(#function),reason:Unknown interruption reason.")
}
}
}
@objc func sessionInterruptionEnded(_ notification: Notification) {
print("看这里:\(#function),Session interruption ended.")
// 你可以在这里恢复会话
}
Apps that have a deployment target earlier than iOS 16 require the com.apple.developer.avfoundation.multitasking-camera-access entitlement to enable accessing the camera while multitasking.
但是目前看下来com.apple.developer.avfoundation.multitasking-camera-access没用
Multitasking modes include Slide Over, Split View, and Picture in Picture (PiP)
Prior to iOS 18, this property is true on iPads that support Stage Manager with an extended display. In apps linked against iOS 18 or later, this property is true for video conferencing apps (those that use voip as one of their UIBackgroundModes). This property also returns true for iOS applications that have the com.apple.developer.avfoundation.multitasking-camera-access entitlement.
问题
resource-intensive capabilities是什么:
Resource-intensive capabilities 是指一些会消耗大量系统资源的功能,通常涉及到高质量的视频和图像处理。例如:
4K 视频捕获:录制高分辨率视频需要较高的 CPU 和 GPU 资源。
Apple ProRAW:拍摄高质量的原始照片文件,通常需要更多的处理和存储资源。
Deep Fusion:一种图像处理技术,通过结合多张照片来提高图像质量,也会消耗大量资源。
为什么启用了resource-intensive capabilities就不建议使用multiTask camera
Enabling multitasking camera access isn’t recommended if your app uses resource-intensive capabilities such as 4K video capture, or Apple ProRAW or Deep Fusion image capture
Split View和Slide Over mode是什么
Split View:一种在 iPad 上的多任务功能,允许用户在屏幕上并排使用两个应用。用户可以调整两个应用的大小,以便更好地利用屏幕空间。
Slide Over Mode:另一种 iPad 上的多任务功能,允许用户在当前应用上方临时显示另一个应用。这使得用户可以快速访问其他应用,而不必完全切换应用。
Stage Manager是什么
Stage Manager 是 iPadOS 的一种多任务处理模式,允许用户以更灵活的方式管理多个应用窗口。它支持将应用以悬浮窗口的形式显示,并允许用户轻松地调整窗口大小和位置,从而增强多任务处理的体验。Stage Manager 旨在为用户提供更直观和更高效的工作空间,使他们能够同时处理多个任务。
324

被折叠的 条评论
为什么被折叠?



