views:

20

answers:

1

I was trying out Apple's sample app SpeakHere, and wanted to listen through the speakerphone speaker instead of the ear speaker.

I was able to turn on the speakerphone speaker using this code:

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); 

But after that the app will no longer record. It freezes. This code doesn't do any good:

    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    
    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
    AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride); 

Boy, it sure seems like if you can toggle the speaker on with top code, you ought to be able to toggle it off with the other code. What's the secret?

A: 

Are you trying to do this while your Audio Queue is running? Or did you stop the audio queue before and restart it after changing the audio session?

Have you looked at the error return values from all the audio session and audio queue calls to see if an error is being reported? And, if so, what is the error value?

hotpaw2
I did not take any notice of the Audio Queue. I just attached the "speaker on" code to the code that executes when the play button is pressed, and the "speaker off" code to the code that executes when the record button is pressed.
Scott Pendleton
Try shutting down the audio queue before you make changes to the audio session type. The user won't notice a glitch if they are expecting the sound output to move. Restart the queue after checking the error status on the session change.
hotpaw2