开发者

iPhone SDK audioSession question

In my app i record and play audio at the same time. The app is almost finished. But there is one thing, that annoying me. When audio session is set to PlayAndRecord, sounds become quiet in comparison with th开发者_运维技巧e same sounds with the SoloAmbient category. Is there any way to make sound louder using PlayAndRecord?


when you use the session for play and record, the playback comes out of the speaker used for the phone, otherwise it comes out the speaker located at the bottom of the phone. this is to prevent feedback. you can override this like so (but watch out for feedback, not an issue if you aren't doing both at once)

    //when the category is play and record the playback comes out of the speaker used for phone conversation to avoid feedback
    //change this to the normal or default speaker

    UInt32 doChangeDefaultRoute = 1;        
    AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof (doChangeDefaultRoute), &doChangeDefaultRoute);

this code works on 3.1.2, earlier sdk's you have to do differently.

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; 
    status = AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);

you have to be careful with this method, it will override even if you have headphones plugged in, you have to monitor interruptions and change the routes accordingly. much better now using 3.1.2


Ask the user to plug in headphones?

The headphone + mic combination doesn't suffer from this problem.

I don't know if it's a bug, a consequence of the audio hardware, or if the quiet playback is just an intentional and hamfisted way of getting cleaner recordings.

UPDATE

I found out that setting the PlayAndRecord session changes your audio route to the receiver.
Apparently the use case is for telephony applications where the user holds the device up to his ear.

If that doesn't violate the Principle of Least Surprise, I don't know what does.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜