10.6之后以编程方式设置Mac OS X卷(Snow Leopard)

时间:2014-07-31 23:54:38

标签: objective-c macos cocoa audiotoolbox

有没有办法使用Objective-C设置Mac的系统音量?我尝试使用:

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

但它在OS X 10.6之后被弃用(Snow Leopard);有一个更好的方法吗?或者我是否需要满足申请量?

1 个答案:

答案 0 :(得分:3)

查看https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/AudioHardwareServicesReference/Reference/reference.html

以下是一些示例代码,假设与您的其他代码具有相同的上下文:

AudioObjectPropertyAddress propertyAddress = { 
    kAudioHardwareServiceDeviceProperty_VirtualMasterVolume, 
    kAudioDevicePropertyScopeOutput,
    kAudioObjectPropertyElementMaster 
};

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