We are working on a software about audio, the function is to record while playing. At the same time, the process can be switched between the handset and the hands-free. However, one problem we found was that the sound became smaller. The specific steps are as follows. First, let's enter in the form of avoiding mention. Suppose the volume is 10, then click the button to switch to the receiver, and then click the button to return to the speakerphone, and find that the volume is reduced, which sounds like the volume is about 6.
if (sender.selected) { /// 听筒 mic
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
} else { /// 免提 hf
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
}