3

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.

Community
  • 1
  • 1
dcrosta
  • 26,009
  • 8
  • 71
  • 83
  • @drcosta - Figuring it out on your own is always a plus but please post it as an answer (and accept it) to your question rather than an edit. That way someone looking for a similar solution won't skip over this page after noticing there are no accepted answers. – Jeff Swensen Apr 28 '11 at 17:54
  • Oh, I didn't realize SO let you accept your own answers now. (At least, I remember thinking at some point in the past that you couldn't). – dcrosta Apr 28 '11 at 19:22

1 Answers1

2

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);
dcrosta
  • 26,009
  • 8
  • 71
  • 83