简体   繁体   中英

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM