开发者

In iOS 5, after the category changed, "AudioQueueStart" used 3 ~ 5 seconds to start recording

After I changed AudioSession's category from kAudioSessionCategory_MediaPlayback to kAudioSessionCategory_PlayAndRecord, the AudioQueueStart method hanged on about 3 ~ 5 seconds to start recording.

The problem only happens on iOS devices running iOS 5, not in Simulator or the devices still running iOS 4 or iOS 3.

Here is what I have tried:

If I don't change the category but always use kAudioSessionCategory_PlayAndRecord, every thing works fine. AudioQueueStart start recording in about 0.01 seconds. But because I want my sound come from the device's speaker, so I can not use kAudioSessionCategory_PlayAndRecord all the time.

Use kAudioSessionOverrideAudioRoute_Speaker and kAudioSessionCategory_PlayAndRecord at the same time is a good idea but if I do so, I should also handle a lo开发者_如何学Ct of kAudioSessionProperty_AudioRouteChange situations such as the user plug in or remove a headphone, connect a bluetooth headset, etc. It is too complex.

Any advice or solution will be appreciated.


Finally I found a way to work around the problem which I believe is an iOS 5's bug.

I set category to kAudioSessionCategory_PlayAndRecord and use the code below:

UInt32 defaultToSpeaker = TRUE;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryDefaultToSpeaker, sizeof(defaultToSpeaker), &defaultToSpeaker);

Note, the kAudioSessionProperty_OverrideCategoryDefaultToSpeaker id only available in iOS 3.1 or greater.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜