【发布时间】:2013-02-27 16:40:56
【问题描述】:
我正在开发 10.8
这是获取当前扬声器音量的代码,
-(float)getVolume{
float volume = 0.0;
UInt32 thePropSize = sizeof(volume);
AudioDeviceID devId = [self GetOutputAudioDevice];
AudioObjectPropertyAddress thePropertyAddress = { kAudioDevicePropertyVolumeScalar, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster };
if(AudioObjectHasProperty(devId, &thePropertyAddress)){
AudioObjectGetPropertyData(devId, &thePropertyAddress, 0, NULL, &thePropSize, &volume);
}else{
printf(" doesn't have property to get the volume");
}
return volume;
}
函数 AudioObjectHasProperty 无法获取 Current Vol 属性,不知道出了什么问题,
这是选择默认输出设备的代码,
-(AudioDeviceID)GetOutputAudioDevice{
OSStatus err;
AudioDeviceID device = 0;
UInt32 size = sizeof(AudioDeviceID);
AudioObjectPropertyAddress address = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
err = AudioObjectGetPropertyData(kAudioObjectSystemObject,
&address,
0,
NULL,
&size,
&device);
if (err)
{
NSLog(@"could not get default audio output device");
}
return device;
}
【问题讨论】:
标签: objective-c macos audio core-audio