tags:

views:

22

answers:

0

Hi all,

I'm developing an app that should have the following properties regarding the audio:

  1. can record and play sound at the same time
  2. can mix the audio output with other app, e.g. iPod
  3. audio output at speaker when earphone is not plugged in
  4. audio output at earphone when it is plugged in

I used the following code.

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *audioSessionError;
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&audioSessionError];

UInt32 mix = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(mix), &mix);

UInt32 route = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(route), &route);

[audioSession setActive:YES error:&audioSessionError];

However, I can achieve 1-3 but failed at 4. When earphone is plugged in, the audio still comes through the speaker. Then I tried setting kAudioSessionProperty_OverrideCategoryDefaultToSpeaker instead of kAudioSessionProperty_OverrideAudioRoute, but this resulted pausing the iPod instead of mixing both audio. Could anyone please help pointing out what's wrong with the above code?

Thanks for any help.