iPhone SDK: Set audio route and also mute audio when mute switch is turned on
I have an application where user can record sound and also play the sound either in the speaker or the ear piece. To route the audio I set kAudioSessionProperty_OverrideAudioRoute in the following way:
if(loudSpeakerOn) {
audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
}
else {
audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
}
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
I should also make sure that when user switches on/off the mute/vibrate switch the sound should mute/unmute. For this I set the following property
SInt32 ambient = kAudioSessionCategory_AmbientSound;
if (AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof(ambient), &ambient)) {
NSLog(@"*** Error *** could not set Session property to ambient.");
}
Now, the problem is when I set the Ambient property, Audio Route and Audio recording stops work开发者_Go百科ing.
How can I get all of these working together?
Thanks!
Did you get this working? I believe setting the audio sessions category ambient will disallow recording. If you need to simultaneously record and play audio, use kAudioSessionCategory_PlayAndRecord instead, otherwise switch back and forth between these when you need them. Also setting the category might reinitialize the routing, so you'll probably want to set that again after setting the category.
精彩评论