2009-12-31 1 views

ответ

1

хорошо я получил это сам ...

theCFString будет содержать UID устройства

UInt32   theSize; 
char   theString[kMaxStringSize]; 
UInt32   theNumberDevices; 
AudioDeviceID *theDeviceList = NULL; 
UInt32   theDeviceIndex; 
CFStringRef  theCFString  = NULL; 
OSStatus  theStatus = noErr; 

// this is our driver 
const char  *nameString = "Burr-Brown Japan PCM2702"; 
const char  *manufacturerString = "Burr-Brown Japan"; 



// device list size 
theSize = 0; 
theStatus = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &theSize, NULL); 


theNumberDevices = theSize/sizeof(AudioDeviceID); 

// allocate the device list 
theDeviceList = (AudioDeviceID*)malloc(theNumberDevices * sizeof(AudioDeviceID)); 

// get the device list 
theSize = theNumberDevices * sizeof(AudioDeviceID); 
theStatus = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &theSize, theDeviceList); 

// iterate through the device list, find our device and return the UID 
for(theDeviceIndex = 0; theDeviceIndex < theNumberDevices; ++theDeviceIndex) 
{ 
    // get name 
    theSize = kMaxStringSize; 
    theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex], 
             0, 0, kAudioDevicePropertyDeviceName, &theSize, theString); 

    NSLog(@"%s",theString); 


    // is it me? 
    if (strncmp(theString, nameString, strlen(nameString)) == 0) { 

     // get manufacturer 
     theSize = kMaxStringSize; 
     theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex], 0, 0, 
              kAudioDevicePropertyDeviceManufacturer, &theSize, theString); 

     NSLog(@"%s",theString); 
     // is it really me? 
     if (strncmp(theString, manufacturerString, strlen(manufacturerString)) == 0) { 
      // get device UID 
      theSize = sizeof(CFStringRef); 
      theStatus = AudioDeviceGetProperty(theDeviceList[theDeviceIndex], 
               0, 0, kAudioDevicePropertyDeviceUID, &theSize, &theCFString); 
      NSLog(@"%s",theCFString); 



      break; 
     } 
    } 
} 
0

AudioHardwareGetProperty является устаревшим в ирбиса.

+0

Да, но эта вещь работает в снежный барс. – 2010-01-07 13:46:44

+1

Поскольку AudioHardwareGetProperty устарел, AudioObjectGetPropertyData должен использоваться вместо этого. Всегда лучше избегать использования устаревших API. – sandeep

19

Чтобы избежать устаревшее AudioHardwareGetProperty и AudioDeviceGetProperty звонки заменить их чем-то вроде этого:

AudioObjectPropertyAddress propertyAddress; 
AudioObjectID    *deviceIDs; 
UInt32      propertySize; 
NSInteger     numDevices; 

propertyAddress.mSelector = kAudioHardwarePropertyDevices; 
propertyAddress.mScope = kAudioObjectPropertyScopeGlobal; 
propertyAddress.mElement = kAudioObjectPropertyElementMaster; 
if (AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize) == noErr) { 
    numDevices = propertySize/sizeof(AudioDeviceID); 
    deviceIDs = (AudioDeviceID *)calloc(numDevices, sizeof(AudioDeviceID)); 

    if (AudioObjectGetPropertyData(kAudioObjectSystemObject, &propertyAddress, 0, NULL, &propertySize, deviceIDs) == noErr) { 
     AudioObjectPropertyAddress  deviceAddress; 
     char       deviceName[64]; 
     char       manufacturerName[64]; 

     for (NSInteger idx=0; idx<numDevices; idx++) { 
      propertySize = sizeof(deviceName); 
      deviceAddress.mSelector = kAudioDevicePropertyDeviceName; 
      deviceAddress.mScope = kAudioObjectPropertyScopeGlobal; 
      deviceAddress.mElement = kAudioObjectPropertyElementMaster; 
      if (AudioObjectGetPropertyData(deviceIDs[idx], &deviceAddress, 0, NULL, &propertySize, deviceName) == noErr) { 
       propertySize = sizeof(manufacturerName); 
       deviceAddress.mSelector = kAudioDevicePropertyDeviceManufacturer; 
       deviceAddress.mScope = kAudioObjectPropertyScopeGlobal; 
       deviceAddress.mElement = kAudioObjectPropertyElementMaster; 
       if (AudioObjectGetPropertyData(deviceIDs[idx], &deviceAddress, 0, NULL, &propertySize, manufacturerName) == noErr) { 
        CFStringRef  uidString; 

        propertySize = sizeof(uidString); 
        deviceAddress.mSelector = kAudioDevicePropertyDeviceUID; 
        deviceAddress.mScope = kAudioObjectPropertyScopeGlobal; 
        deviceAddress.mElement = kAudioObjectPropertyElementMaster; 
        if (AudioObjectGetPropertyData(deviceIDs[idx], &deviceAddress, 0, NULL, &propertySize, &uidString) == noErr) { 
         NSLog(@"device %s by %s id %@", deviceName, manufacturerName, uidString); 

         CFRelease(uidString); 
        } 
       } 
      } 
     } 
    } 

    free(deviceIDs); 
} 
+1

Если бы я мог это сделать снова, я бы это сделал. Я попытался это сделать сам, но не смог найти никакой документации. Насколько я могу сказать, это единственное место во всех интернетах, что это документировано. – hooleyhoop