views:

389

answers:

1

Hi,

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 working.

How can I get all of these working together?

Thanks!

A: 

Hi Mithin! 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.