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

问题描述 投票:1回答:1

是否有一种使用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(雪豹)之后不推荐使用;有一个更好的方法吗?还是我必须满足申请量?

objective-c macos cocoa audiotoolbox
1个回答
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);
© www.soinside.com 2019 - 2024. All rights reserved.