问题
Please edvice by objective-c code snippets and useful links of how can I control all audio signals of output in OS X?
I think it should be something like proxy layer somewhere in OS X logic layers.
Thank you!
回答1:
It's somewhat sad that there is no simple API to do this. Luckily it isn't too hard, just verbose.
First, get the system output device:
UInt32 size;
AudioDeviceID outputDevice;
OSStatus result = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOuputDevice, &size, &outputDevice);
Then set the volume:
Float32 theVolume;
result = AudioDeviceSetProperty(theDevice, NULL, 0, /* master channel */ false, kAudioDevicePropertyVolumeScalar, sizeof(Float32), &theVolume);
Obviously I've omitted any error checking, which is a must.
Things can get a bit tricky because not all devices support channel 0 (the master channel). If this is the case with your device (it probably is) you have two options: query the device for its preferred stereo pair and set the volume on those channels individually, or just set the volume on channels 1 and 2.
来源:https://stackoverflow.com/questions/5109971/controlling-volume-of-running-applications-in-mac-os-x-via-objective-c