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 speaker:
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOverride), &audioRouteOverride);
This works fine. But now, I'd like to route the sound through the headphones when headphones or external speakers are attached. How would I achieve that?
Also ideally all other sound (i.e. music etc.) should mute when the app launches.
Thanks!