AVCaptureSession:添加/删除DeviceInput

时间:2013-04-24 08:01:21

标签: iphone ios

我正在尝试实现一个功能,您可以在AVCaptureSession期间启用或禁用麦克风。这是我启用设备的方法(初始化)

-(void)initMicrophoneInput:(AVCaptureSession*)session{
    AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
    _microphoneInput = [[AVCaptureDeviceInput alloc] initWithDevice:audioDevice error:nil];
    if ([session canAddInput:_microphoneInput]){
        [session addInput:_microphoneInput];
    } else {
        NSLog(@"can't add input");
    }
}

这是我禁用/启用麦克风的功能:

- (IBAction)manageMicrophone:(id)sender {
    [_captureSession beginConfiguration];
    if(_microphoneMuted == NO){
        [_captureSession removeInput:_microphoneInput];
    }else{
        [self initMicrophoneInput:_captureSession];
    }
    [_captureSession commitConfiguration];
    _microphoneMuted = !_microphoneMuted;
}

初始化和移除麦克风效果很好,但我无法再次启用麦克风。我的_captureSession.inputs包含“微型”设备,但我不再从- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;

获取音频样本

0 个答案:

没有答案