I’m constructing an iOS app utilizing Twilio Video 5.10 with Swift. The app helps video calls and works accurately in Image in Image (PiP) mode.
Nevertheless, I’ve observed a problem:
- After I activate PiP, the native digital camera feed streams usually to the distant participant.
- If I swipe the PiP window offscreen (hidden on the fringe of the show), the distant participant sees my video frozen.
- Audio continues working, however the video stays frozen till I carry the PiP window again onscreen.
Is that this anticipated habits in iOS PiP with Twilio Video, or is there a workaround to maintain the digital camera feed lively whereas the PiP window is hidden?
I set my CameraSourceOptions enableCameraMultitasking to true
additionally added com.apple.developer.avfoundation.multitasking-camera-access to my .entitlements
right here my CameraManager class:
import TwilioVideo
import AVFoundation
protocol CameraManagerDelegate: AnyObject {
func trackSourceWasInterrupted(observe: LocalVideoTrack)
func trackSourceInterruptionEnded(observe: LocalVideoTrack)
}
remaining class CameraManager: NSObject {
weak var delegate: CameraManagerDelegate?
let observe: LocalVideoTrack
personal let supply: CameraSource
var place: AVCaptureDevice.Place {
get { supply.system?.place ?? .unspecified }
set {
guard let system = CameraSource.captureDevice(place: newValue) else {
print("No seize system for (newValue)")
return
}
supply.selectCaptureDevice(system) { _, _, error in
if let error { print("Choose system error: (error)") }
}
}
}
deinit { supply.stopCapture() }
init?(place: AVCaptureDevice.Place = .entrance) {
let choices = CameraSourceOptions { builder in
builder.enableCameraMultitasking = true
}
guard let supply = CameraSource(choices: choices, delegate: nil) else {
print("Unable to create CameraSource"); return nil
}
guard let observe = LocalVideoTrack(supply: supply, enabled: true, title: "digital camera") else {
print("Unable to create LocalVideoTrack"); return nil
}
self.supply = supply
self.observe = observe
tremendous.init()
self.supply.delegate = self
if let system = CameraSource.captureDevice(place: place) {
let config = CameraConfigFactory().makeCameraConfigFactory(captureDevice: system)
supply.requestOutputFormat(config.outputFormat)
supply.startCapture(system: system, format: config.inputFormat) { _, _, error in
if let error { print("Begin seize error: (error)") }
}
}
}
}
extension CameraManager: CameraSourceDelegate {
func cameraSourceWasInterrupted(supply: CameraSource, purpose: AVCaptureSession.InterruptionReason) {
print("Digicam interruption started: (purpose)")
delegate?.trackSourceWasInterrupted(observe: observe)
}
func cameraSourceInterruptionEnded(supply: CameraSource) {
print("Digicam interruption ended")
delegate?.trackSourceInterruptionEnded(observe: observe)
}
func cameraSourceDidFail(supply: CameraSource, error: any Error) {
print("Digicam supply failed: (error)")
}
}