Adjusting the Mac OS X volume after 10.6 (Snow Leopard)

Is there a way to set the volume of a Mac system using Objective-C? I tried with:

AudioDeviceSetProperty([[self class]defaultOutputDeviceID],
                       NULL, //time stamp not needed
                       0, //channel 0 is master channel
                       false,  //for an output device
                       kAudioDevicePropertyVolumeScalar,
                       sizeof(Float32),
                       &volume);

      

But this has been deprecated since OS X 10.6 (Snow Leopard); Is there a better way to do this? Or will I have to be content with the volume of the application?

+1


source to share


1 answer


Check out https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/AudioHardwareServicesReference/Reference/reference.html

Here's some sample code, assuming the same context as your other code:



AudioObjectPropertyAddress propertyAddress = { 
    kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, 
    kAudioDevicePropertyScopeOutput,
    kAudioObjectPropertyElementMaster 
};

AudioHardwareServiceSetPropertyData([self.class defaultOutputDeviceID], 
                                    &propertyAddress, 
                                    0, 
                                    NULL, 
                                    sizeof(Float32),
                                    &volume);

      

+3


source







All Articles