2011-07-19 20 views

cevap

9

Bu, bazı ses aygıtlarının bir ana kanalı desteklemesi nedeniyle bu biraz zor olabilir, ancak çoğu böyle olmazsa, birim kanal başına bir özellik olacaktır. Ne yapmanız gerektiğine bağlı olarak, yalnızca bir kanalı gözlemleyebilir ve cihazın desteklediği diğer tüm kanalların aynı hacme sahip olduğunu varsayabilirsiniz. Ne olursa olsun, izlemek istediğiniz kaç kanal nedeniyle, söz konusu AudioObject için bir özellik dinleyici kaydederek hacmini gözlemlemek:

// Some devices (but not many) support a master channel 
AudioObjectPropertyAddress propertyAddress = { 
    kAudioDevicePropertyVolumeScalar, 
    kAudioDevicePropertyScopeOutput, 
    kAudioObjectPropertyElementMaster 
}; 

if(AudioObjectHasProperty(deviceID, &propertyAddress)) { 
    OSStatus result = AudioObjectAddPropertyListener(deviceID, &propertyAddress, myAudioObjectPropertyListenerProc, self); 
    // Error handling omitted 
} 
else { 
    // Typically the L and R channels are 1 and 2 respectively, but could be different 
    propertyAddress.mElement = 1; 
    OSStatus result = AudioObjectAddPropertyListener(deviceID, &propertyAddress, myAudioObjectPropertyListenerProc, self); 
    // Error handling omitted 

    propertyAddress.mElement = 2; 
    result = AudioObjectAddPropertyListener(deviceID, &propertyAddress, myAudioObjectPropertyListenerProc, self); 
    // Error handling omitted 
} 

telsizinde proc olması gereken bir şey gibi:

static OSStatus 
myAudioObjectPropertyListenerProc(AudioObjectID       inObjectID, 
            UInt32        inNumberAddresses, 
            const AudioObjectPropertyAddress  inAddresses[], 
            void         *inClientData) 
{ 
    for(UInt32 addressIndex = 0; addressIndex < inNumberAddresses; ++addressIndex) { 
     AudioObjectPropertyAddress currentAddress = inAddresses[addressIndex]; 

     switch(currentAddress.mSelector) { 
      case kAudioDevicePropertyVolumeScalar: 
      { 
       Float32 volume = 0; 
       UInt32 dataSize = sizeof(volume); 
       OSStatus result = AudioObjectGetPropertyData(inObjectID, &currentAddress, 0, NULL, &dataSize, &volume); 

       if(kAudioHardwareNoError != result) { 
        // Handle the error 
        continue; 
       } 

       // Process the volume change 

       break; 
      } 
     } 
    } 
} 
İlgili konular