我正在编写一个将音频切换到扬声器的功能:
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
但是当我尝试使用它将其切换回耳机时:
UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);
此代码适用于iPhone但在iPad中不能从扬声器切换到耳机,任何一个指南有什么不同吗?
答案 0 :(得分:0)
尝试将UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback
更改为UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord