獲取手機音頻輸出設備方法

iOS上所有可能的輸出設備:

  1. /* Known values of route: 
  2. * "Headset" 
  3. * "Headphone" 
  4. * "Speaker" 
  5. * "SpeakerAndMicrophone" 
  6. * "HeadphonesAndMicrophone" 
  7. * "HeadsetInOut" 
  8. * "ReceiverAndMicrophone" 
  9. * "Lineout" 
  10. */  
以下是獲得當前手機的輸出設備方法

CFDictionaryRef currentRouteDescriptionDictionary = nil;

UInt32 dataSize = sizeof(currentRouteDescriptionDictionary);

AudioSessionGetProperty(kAudioSessionProperty_AudioRouteDescription, &dataSize, &currentRouteDescriptionDictionary);

if (currentRouteDescriptionDictionary) {

CFArrayRef outputs = CFDictionaryGetValue(currentRouteDescriptionDictionary, kAudioSession_AudioRouteKey_Outputs);

if (outputs) {

if(CFArrayGetCount(outputs) > 0) {

for (int i=0; i<CFArrayGetCount(outputs); i++) {

CFDictionaryRef output = CFArrayGetValueAtIndex(outputs, i);

CFStringRef outputType = CFDictionaryGetValue(output, kAudioSession_AudioRouteKey_Type);

NSLog(@" audio route type is %@",outputType);

}

}

}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章