ios – video freezes when Image-in-Image is hidden offscreen

0
6
ios – video freezes when Image-in-Image is hidden offscreen


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:

  • Once 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 deliver the PiP window again onscreen.

Is that this anticipated conduct in iOS PiP with Twilio Video, or is there a workaround to maintain the digital camera feed energetic 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
    non-public let supply: CameraSource

    var place: AVCaptureDevice.Place {
        get { supply.machine?.place ?? .unspecified }
        set {
            guard let machine = CameraSource.captureDevice(place: newValue) else {
                print("No seize machine for (newValue)")
                return
            }
            supply.selectCaptureDevice(machine) { _, _, error in
                if let error { print("Choose machine 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 machine = CameraSource.captureDevice(place: place) {
            let config = CameraConfigFactory().makeCameraConfigFactory(captureDevice: machine)
            supply.requestOutputFormat(config.outputFormat)
            supply.startCapture(machine: machine, format: config.inputFormat) { _, _, error in
                if let error { print("Begin seize error: (error)") }
            }
        }
    }
}

extension CameraManager: CameraSourceDelegate {
    func cameraSourceWasInterrupted(supply: CameraSource, cause: AVCaptureSession.InterruptionReason) {
        print("Digital camera interruption started: (cause)")
        delegate?.trackSourceWasInterrupted(observe: observe)
    }

    func cameraSourceInterruptionEnded(supply: CameraSource) {
        print("Digital camera interruption ended")
        delegate?.trackSourceInterruptionEnded(observe: observe)
    }

    func cameraSourceDidFail(supply: CameraSource, error: any Error) {
        print("Digital camera supply failed: (error)")
    }
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here