iPhone AudioSession性质 [英] iPhone AudioSession properties
问题描述
我开发一个应用程序,应该有关于音频以下属性:
I'm developing an app that should have the following properties regarding the audio:
- 可以记录并同时播放声音
- 可以混合与其他应用程序,例如音频输出iPod的
- 在扬声器的音频输出耳机时没有插入
- 在耳机音频输出,当它被插入
我用下面的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];
不过,我可以达到1-3,但在4失败当耳机插入,音频仍然来自通过扬声器。然后我试着设置的 kAudioSessionProperty_OverrideCategoryDefaultToSpeaker
而不是 kAudioSessionProperty_OverrideAudioRoute
,但是这导致暂停的iPod,而不是混合音频。任何人都可以请帮助指出有什么不对上述code?
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?
感谢您的帮助。
推荐答案
我觉得这样的:
UInt32 route = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty(kAudioSessionProperty_OverrideAudioRoute, sizeof(route), &route);
具体是指使用扬声器。默认操作(插入时使用耳机)应该是:
Specifically means use the speaker. The default action (to use the headphones when plugged in) should be:
UInt32 route = kAudioSessionOverrideAudioRoute_None;
这篇关于iPhone AudioSession性质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!