AVAudioSession *audioSession = [AVAudioSession sharedInstance];
// 设置为内置麦克风采集
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVideoRecording options:nil error:nil];
// 切换输入麦克风
AVAudioSessionPortDescription *builtInMicPort = nil;
for (AVAudioSessionPortDescription *portDescription in audioSession.availableInputs) {
if ([portDescription.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
builtInMicPort = portDescription;
break;
}
}
if (builtInMicPort) {
NSError *inputError = nil;
[audioSession setPreferredInput:builtInMicPort error:&inputError];
if (inputError) {
NSLog(@"切换输入麦克风失败:%@", inputError);
}else{
NSLog(@"内置麦克风");
}
} else {
NSLog(@"找不到内置麦克风");
}
[audioSession setActive:YES error:nil];
set mode AVAudioSessionModeVideoRecording normall
Post
Replies
Boosts
Views
Activity
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
// 设置为内置麦克风采集
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord mode:AVAudioSessionModeVideoRecording options:nil error:nil];
// 切换输入麦克风
AVAudioSessionPortDescription *builtInMicPort = nil;
for (AVAudioSessionPortDescription *portDescription in audioSession.availableInputs) {
if ([portDescription.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
builtInMicPort = portDescription;
break;
}
}
if (builtInMicPort) {
NSError *inputError = nil;
[audioSession setPreferredInput:builtInMicPort error:&inputError];
if (inputError) {
NSLog(@"切换输入麦克风失败:%@", inputError);
}else{
NSLog(@"内置麦克风");
}
} else {
NSLog(@"找不到内置麦克风");
}
[audioSession setActive:YES error:nil];
work normal