Controlling OS X volume in Snow Leopard

随声附和 提交于 2019-12-10 10:24:46

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/5286092/controlling-os-x-volume-in-snow-leopard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!