Our app uses the remoteIO (audio-unit) to get audio input from mic, and DSP over it in real time, it has a callback function that gives me the buffer, and I work on it.
At the same time, we need to play sounds over avAudioPlayer.
I put in my init this : (route the sounds to speaker and let it play and record)
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
but then I have seen something strange. The sounds are playing from the small speaker - the one you use to put your ears on, in phone calls.
Then I did a trick. I have seen that in order to really route the sounds to the speakers, I have to play something and in the same time execute this 4 lines above. If I do it 1 time, then the sounds are moving back to the speakers forever. I did that with a timer that calls the method, and the moment this method executes them, I play sound with avaudioPlayer, then-it fix it and sound routes to speakers.
Any one has any solution, or explanation about that thing? I really need to play sounds via speakers, without tricks.