使用XCode设置Mac OSX卷
问题描述:
有什么方法使用Objective C设置Mac系统音量?我尝试使用:
Is there any way to set Mac System Volume using Objective C? I tried using:
AudioDeviceSetProperty([[self class]defaultOutputDeviceID],
NULL, //time stamp not needed
0, //channel 0 is master channel
false, //for an output device
kAudioDevicePropertyVolumeScalar,
sizeof(Float32),
&volume);
但是OSX 10.6之后就不推荐使用了。有没有更好的方法来做到这一点?
But it is deprecated after OSX 10.6; is there a better way to do this? Or will I have to settle for application volume.
答
这里是一些假设与其他代码相同的上下文的示例代码
here is 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);