3

I am facing very weird issue while switching between camera. When user switch the camera from front to rear, user can see the red status bar for a second then disappears automatically with slide up animation. I searched a lot on google & stack-overflow but no luck. I found this question , but its related to audio recording. Here is my code

-(void)toggleCameraIsFront:(BOOL)isFront
{
    AVCaptureDevicePosition desiredPosition;
    if (isFront) {
        desiredPosition = AVCaptureDevicePositionFront;
        self.videoDeviceType = VideoDeviceTypeFrontCamera;
    }
    else {
        desiredPosition = AVCaptureDevicePositionBack;
        self.videoDeviceType = VideoDeviceTypeRearCamera;
    }

    for (AVCaptureDevice *d in [AVCaptureDevice devicesWithMediaType: AVMediaTypeVideo])
    {
        if ([d position] == desiredPosition)
        {
            AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:d error:nil];
            [self.session beginConfiguration];
            [self.session removeInput:self.videoInput];
            if ([self.session canAddInput:videoDeviceInput])
            {
                [self.session addInput:videoDeviceInput];
                [self setVideoInput:videoDeviceInput];
            }
            else
            {
                [self.session addInput:self.videoInput];
            }
            [self.session commitConfiguration];
            break;
        }
    }
 }

Also after camera is switched & try to record the video then below method from AVCaptureVideoDataOutputSampleBufferDelegate not getting called.

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

Any kind of help is highly appreciated. Thanks.

Community
  • 1
  • 1
Nitin
  • 241
  • 2
  • 11

1 Answers1

0

This red status bar appears due to audio recording, as you've mentioned a question which also describe that this is due to audio recording. In order to avoid this you need to remove the audio input from AVCaptureSession

[self.captureSession removeInput:audioInput];

where audioInput is AVCaptureDeviceInput object.

Please check @bruno answer for more clarification.

Community
  • 1
  • 1
Muhammad Umair
  • 1,664
  • 2
  • 20
  • 28