dcrosta
dcrosta

Reputation: 26258

Controlling OS X volume in Snow Leopard

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.

Upvotes: 3

Views: 1174

Answers (1)

dcrosta
dcrosta

Reputation: 26258

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);

Upvotes: 2

Related Questions