问题
This is a follow up to Controlling volume of running applications in Mac OS X via Objective-C, which explains how to set the volume for 10.5 or earlier. The AudioXXXXXGetProperty
, and AudioXXXXXSetProperty
(and related) functions are deprecated in 10.6, per Technical Note TN2223.
I'm not an expert in OS X or CoreAudio programming, so I'm hoping someone has muddled through what's required in Snow Leopard and can help me (and others) out here.
回答1:
Here's an example to set volume to 50%:
Float32 volume = 0.5;
UInt32 size = sizeof(Float32);
AudioObjectPropertyAddress address = {
kAudioDevicePropertyVolumeScalar,
kAudioDevicePropertyScopeOutput,
1 // use values 1 and 2 here, 0 (master) does not seem to work
};
OSStatus err;
err = AudioObjectSetPropertyData(device, &address, 0, NULL, size, &volume);
来源:https://stackoverflow.com/questions/5286092/controlling-os-x-volume-in-snow-leopard