gpt4 book ai didi

macos - 在Mac OS X上使用AudioUnit检测扬声器/耳机

转载 作者:行者123 更新时间:2023-12-03 00:19:00 26 4
gpt4 key购买 nike

使用AudioUnit和kAudioUnitSubType_HALOutput如何检测输出是Speaker还是Headset?

最佳答案

bool usingInternalSpeakers()
{
AudioDeviceID defaultDevice = 0;
UInt32 defaultSize = sizeof(AudioDeviceID);

const AudioObjectPropertyAddress defaultAddr = {
kAudioHardwarePropertyDefaultOutputDevice,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};

AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultAddr, 0, NULL, &defaultSize, &defaultDevice);

AudioObjectPropertyAddress property;
property.mSelector = kAudioDevicePropertyDataSource;
property.mScope = kAudioDevicePropertyScopeOutput;
property.mElement = kAudioObjectPropertyElementMaster;

UInt32 data;
UInt32 size = sizeof(UInt32);
AudioObjectGetPropertyData(defaultDevice, &property, 0, NULL, &size, &data);

return data == 'ispk';
}


int main(int argc, const char * argv[])
{


if (usingInternalSpeakers())
printf("I'm using the speakers!");
else
printf("i'm using the headphones!");
return 0;
}

关于macos - 在Mac OS X上使用AudioUnit检测扬声器/耳机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15728513/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com