我希望能够使用Core Audio获取和设置系统音量级别。我已经按照这个线程上的代码进行尝试: objective c audio meter
然而,我的调用AudioHardwareServiceHasProperty
函数来查找kAudioHardwareServiceDeviceProperty_VirtualMasterVolume
属性时返回false。为什么会发生这种情况,我该如何解决?采用什么方式可以获取和设置系统音量级别?
我希望能够使用Core Audio获取和设置系统音量级别。我已经按照这个线程上的代码进行尝试: objective c audio meter
然而,我的调用AudioHardwareServiceHasProperty
函数来查找kAudioHardwareServiceDeviceProperty_VirtualMasterVolume
属性时返回false。为什么会发生这种情况,我该如何解决?采用什么方式可以获取和设置系统音量级别?
你尝试过使用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