gpt4 book ai didi

ios - AVCaptureSession如何使静音输入音频设备?

转载 作者:行者123 更新时间:2023-12-02 23:53:46 35 4
gpt4 key购买 nike

这就是我尝试使用button配置打开/关闭麦克风音量的方式:

//micBtn turn on/off
- (void)micTap:(UIButton*)sender
{
if (sender.selected) {
[self addAudioInput];
} else {
[self removeVideoInput:NO audioInput:YES];
}
}

- (void)removeVideoInput:(BOOL)removeVI audioInput:(BOOL)removeAI
{
NSArray *inputs = self.session.inputs;

for (AVCaptureDeviceInput *input in inputs) {

if (removeVI && [input.device hasMediaType:AVMediaTypeVideo]) {

[self.session removeInput:input];
continue;
}

if (removeAI && [input.device hasMediaType:AVMediaTypeAudio]) {

[self.session removeInput:input];
}
}

}


- (BOOL)addAudioInput //returns success of adding
{
NSArray *inputs = self.session.inputs;

BOOL alreadyHasAudioInput = NO;

for (AVCaptureDeviceInput *input in inputs) {
if ([input.device hasMediaType:AVMediaTypeAudio]) {
alreadyHasAudioInput = YES;

}
}

if (alreadyHasAudioInput) {
return NO;
}

AVCaptureDevice *audio = [AVCaptureDevice devices][kAudioType];

AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audio error:nil];

[self.session beginConfiguration];

[self.session addInput:audioInput];

[self.session commitConfiguration];

return YES;
}

当我打开/关闭麦克风时,它会停止记录并出现以下错误:

  • (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error


在日志中,我看到@“错误:录制已停止”。

最佳答案

您应该像添加音频输入一样,以'[self.session beginConfiguration]'开始'removeVideoInput:audioInput:'方法,并以'[self.session commitConfiguration]'结尾。这使您在 session 上进行的所有更改都自动发生。

关于ios - AVCaptureSession如何使静音输入音频设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20067067/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com