使用XCode设置Mac OSX卷 [英] Setting Mac OSX Volume Programatically using XCode

查看:174
本文介绍了使用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.

推荐答案

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

这里是一些假设与其他代码相同的上下文的示例代码

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

这篇关于使用XCode设置Mac OSX卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆