【问题标题】:Red status bar shown while switching camera using AVFoundation使用 AVFoundation 切换相机时显示红色状态栏
【发布时间】:2014-03-12 09:42:45
【问题描述】:

在相机之间切换时,我遇到了非常奇怪的问题。当用户从前到后切换相机时,用户可以看到红色状态栏一秒钟,然后随着上滑动画自动消失。我在 google 和 stack-overflow 上搜索了很多,但没有运气。我找到了这个 question ,但它与 audio recording 有关。这是我的代码

-(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;
        }
    }
 }

另外,在切换相机并尝试录制视频后,AVCaptureVideoDataOutputSampleBufferDelegate 的以下方法不会被调用。

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

我们非常感谢任何形式的帮助。谢谢。

【问题讨论】:

    标签: ios camera avfoundation avcapturesession


    【解决方案1】:

    此红色状态栏是由于录音而出现的,因为您提到了一个问题,该问题也描述了这是由于录音造成的。 为了避免这种情况,您需要从AVCaptureSession中删除音频输入

    [self.captureSession removeInput:audioInput];
    

    其中 audioInputAVCaptureDeviceInput 对象。

    请查看@bruno 答案以获得更多说明。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      相关资源
      最近更新 更多