本文介绍了在10.6之后以编程方式设置Mac OS X音量(Snow Leopard)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用Objective-C设置Mac的系统音量?我尝试使用:
Is there a way to set the Mac's 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);
但是在 OS X 10.6 (Snow Leopard)之后,它已被弃用;有一个更好的方法吗?还是我必须满足申请量?
But it is deprecated after OS X 10.6 (Snow Leopard); is there a better way to do this? Or will I have to settle for application volume?
推荐答案
在AudioToolbox中检查音频硬件服务:
Check out Audio Hardware Services in AudioToolbox:
- AudioToolbox Functions
- Audio Hardware Services Properties
以下是一些示例代码,它们假定与您的其他代码具有相同的上下文:
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);
这篇关于在10.6之后以编程方式设置Mac OS X音量(Snow Leopard)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!