Search code examples
iosswiftavcapturesession

AVCaptureSession commitConfiguration() takes too long


Bellow is my Swift code for switching between front and back camera. Commit configuration takes 9 seconds on the first switch, does anyone knows why?

        captureSession!.beginConfiguration()
        captureSession!.removeInput(activeVideoInput)
        if captureSession!.canAddInput(videoInput) {
            captureSession!.addInput(videoInput)
            activeVideoInput = videoInput
        }
        captureSession!.commitConfiguration()

Solution

  • I was facing similar problem, plus I was getting sometimes a black screen and only on ios 8.4 after I updated xCode.

    Anw the problem was this:

    _captureSession.automaticallyConfiguresApplicationAudioSession = NO;
    _captureSession.usesApplicationAudioSession=YES;
    

    I was calling these 2 lines before

    [self.captureSession startRunning];
    

    Just moving them after startRunning made everything work, if this wasn't the case for you, try to find something special you are doing before startRunning and put it after it.

    Gd Luck.