imaginary-cloud/CameraManager

Multiple audio/video AVCaptureInputs are not currently supported

pablogupi opened this issue · 6 comments

Hi! I have encountered this random error in version 5.1.3 . I try to change continuously and it works perfectly. Can you think of a way to replicate it to try to correct it? Thank you very much

Fatal Exception: NSInvalidArgumentException
0 CoreFoundation 0x18cf7c360 (Falta)
1 libobjc.A.dylib 0x18cc9f090 (Falta)
2 AVFCapture 0x1cc21b7a0 (Falta)
3 CameraManager 0x102e16fb4 CameraManager.setupOutputMode(:oldCameraOutputMode:) + 1613 (CameraManager.swift:1613)

captureSession?.addInput(validMic)

4 CameraManager 0x102e244a4 partial apply for closure 1 in CameraManager.setupCamera(:) + 1634 (CameraManager.swift:1634)
if let validCaptureSession = captureSession {

5 CameraManager 0x102e1065c thunk for @escaping @callee_guaranteed () -> () ()
6 libdispatch.dylib 0x18cc3b578 (Falta)
7 libdispatch.dylib 0x18cc3c560 (Falta)
8 libdispatch.dylib 0x18cbe557c (Falta)
9 libdispatch.dylib 0x18cbe6058 (Falta)
10 libdispatch.dylib 0x18cbefaf0 (Falta)
11 libsystem_pthread.dylib 0x18cc935a4 (Falta)
12 libsystem_pthread.dylib 0x18cc96874 (Falta)

@pablogupi

can you share your CameraManager setup? It would help me replicate the issue.

Yes, this is my code relationated :

 fileprivate func setupCameraManager() {
        
        self.restoreView();
        
        cameraManager.shouldEnableExposure = true
        cameraManager.shouldRespondToOrientationChanges=true
        cameraManager.writeFilesToPhoneLibrary = false
        
        cameraManager.shouldFlipFrontCameraImage = false
        cameraManager.showAccessPermissionPopupAutomatically = false
        cameraManager.cameraOutputQuality = .high
        cameraManager.shouldKeepViewAtOrientationChanges=false
  
    }

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
      super.willTransition(to: newCollection, with: coordinator)

if windowInterfaceOrientation.isLandscape {
              self.restoreView()
              self.addCameraToView()
              self.cameraManager.resetOrientation()
          } else {
              self.restoreView()
              self.addCameraToView()
              self.cameraManager.resetOrientation()
              
          }
}
 fileprivate func addCameraToView() {
        cameraManager.addPreviewLayerToView(previewView, newCameraOutputMode: CameraOutputMode.videoWithMic)

    
        cameraManager.showErrorBlock = { [weak self] (erTitle: String, erMessage: String) -> Void in
            
            let alertController = UIAlertController(title: erTitle, message: erMessage, preferredStyle: .alert)
            alertController.addAction(UIAlertAction(title: "btn_ok".localized, style: UIAlertAction.Style.default, handler: { (_) -> Void in }))
            
            self?.present(alertController, animated: true, completion: nil)
        }


}

    @objc func changeCameraDevice() {
        cameraManager.cameraDevice = cameraManager.cameraDevice == CameraDevice.back ? CameraDevice.front : CameraDevice.back
        
    } `

That's it. Thanks

@pablogupi

thanks for the code. Looking into your willTransition method:

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
      super.willTransition(to: newCollection, with: coordinator)

if windowInterfaceOrientation.isLandscape {
              self.restoreView()
              self.addCameraToView()
              self.cameraManager.resetOrientation()
          } else {
              self.restoreView()
              self.addCameraToView()
              self.cameraManager.resetOrientation()
              
          }
}

it appears you are calling self.addCameraToView() every-time the collection is changed, is that correct?
If so, you should call that only once, otherwise you would be calling cameraManager.addPreviewLayerToView(previewView, newCameraOutputMode: CameraOutputMode.videoWithMic) more than once.

Let me know if that was the case.

Thanks for your response @torrao
This is because I need the when the screen rotates, the camera also. If I deactivate that code and leave it like that, when I turn the screen the camera appears only in half screen.

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        super.willTransition(to: newCollection, with: coordinator)
        
        coordinator.animate(alongsideTransition: { (context) in
            guard let windowInterfaceOrientation = self.windowInterfaceOrientation else { return }
            self.view.willRemoveSubview(self.previewView)
            
            self.cameraManager.resetOrientation()

        })
    }

IMG_6479
IMG_6480

@pablogupi

spent some time trying to replicate your issue with the code you provided and I was unable to trigger the error.

Hi! Apparently when I have the camera in .videoOnly mode it works fine. At the moment the error does not appear: "Multiple audio / video AVCaptureInputs are not currently supported". Only occurs in videoWithMic mode