I have an app which does listen and play sound at the same time. By default, the sound output goes through the earphone. So I use the following code to route it through the spea
This is a quick and dirty way and seems to work for me:
void sessionPropertyListener(void * inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void * inData){ if (inID == kAudioSessionProperty_AudioRouteChange) { CFStringRef newRoute; UInt32 size = sizeof(CFStringRef); AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &newRoute); if (newRoute) { CFShow(newRoute); if (CFStringCompare(newRoute, CFSTR("ReceiverAndMicrophone"), (UInt32)NULL) == kCFCompareEqualTo)//if receiver, play through speakers { UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride); } else if (CFStringCompare(newRoute, CFSTR("HeadsetInOut"), (UInt32)NULL) == kCFCompareEqualTo)//headset { UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride); } } } }