我在使用扬声器和麦克风切换音频时遇到问题。首先,当应用程序启动音频播放到默认扬声器时。然后在按钮事件上,我将其更改为在麦克风中播放的麦克风。
但是当我尝试切换回扬声器时,它对我不起作用,它在麦克风中播放。
代码
- (IBAction)setSpeakerPhoneEnabled:(UIButton *)sender
{
AVAudioSession* session = [AVAudioSession sharedInstance];
BOOL success;
NSError* error;
if (isHeadPhone) {
[session setCategory:AVAudioSessionCategoryPlayAndRecord
error:&error];
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
}
else{
success = [session setCategory:AVAudioSessionCategoryPlayback
error:&error];
UInt32 audioRouteOverride = kAudioSessionOutputRoute_Headphones;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
}
isHeadPhone = !isHeadPhone;
[self setTheSpekerImage];
}
当我做错时请告诉我