da1lbi3
da1lbi3

Reputation: 4519

Multiple audio/video AVCaptureInputs are not currently supported

I get the following error: Multiple audio/video AVCaptureInputs are not currently supported. This issue occurs with the following row:

 g.captureSession.addInput(AVCaptureDeviceInput(device: captureDevice))

So I searched on the internet and saw this solution:

if(g.captureSession.inputs.isEmpty){
   try g.captureSession.addInput(AVCaptureDeviceInput(device: captureDevice))
}

But this doesn't work either because it is not empty?! even if it is the first time. So the input is never added.

This is my actual code:

let g = peerConnectionFactory.avFoundationVideoSource(with: nil);
        g.captureSession.sessionPreset = AVCaptureSessionPresetHigh

    let devices = AVCaptureDevice.devices()
    for device in devices! {
        if ((device as AnyObject).hasMediaType(AVMediaTypeVideo)) {
            if((device as AnyObject).position == AVCaptureDevicePosition.front) {
                let captureDevice = device as? AVCaptureDevice
                if captureDevice != nil {

                    do{
                        try g.captureSession.addInput(AVCaptureDeviceInput(device: captureDevice))

                        g.captureSession.startRunning()
                    } catch {
                        print("we have error")
                    }

                }
            }
        }
    }

How can I solve this issue? And what am I doing wrong?

Upvotes: 0

Views: 1434

Answers (1)

Hope
Hope

Reputation: 2326

You are adding more than one input because device you are working with more than one camera.

So you are getting error.

First find and store devices.

Then use addInput for just one of them.

Upvotes: 0

Related Questions