2
votes

I want to be able to get and set the system volume level with Core Audio. I've followed the code on this other thread: objective c audio meter

However, my call to AudioHardwareServiceHasProperty to find the kAudioHardwareServiceDeviceProperty_VirtualMasterVolume property returns false. Why is this happening, and how do I get around it? What approach should I take to getting and setting the system volume level with Core Audio?

1

1 Answers

3
votes

Have you tried kAudioDevicePropertyVolumeScalar:

UInt32 channel = 1; // Channel 0  is master, if available
AudioObjectPropertyAddress prop = { 
    kAudioDevicePropertyVolumeScalar, 
    kAudioDevicePropertyScopeOutput,
    channel 
};

if(!AudioObjectHasProperty(deviceID, &prop))
    // error

Float32 volume;
UInt32 dataSize = sizeof(volume);
OSStatus result = AudioObjectGetPropertyData(deviceID, &prop, 0, NULL, &dataSize, &volume);

if(kAudioHardwareNoError != result)
    // error