开发者

Controlling volume of running applications in Mac OS X via Objective-C

Please edvice by objective-c code snippets and useful links of how can I control all audio signals of o开发者_运维知识库utput in OS X?

I think it should be something like proxy layer somewhere in OS X logic layers.

Thank you!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜