0
AudioUnit 및 kAudioUnitSubType_HALOutput을 사용하면 출력이 스피커 또는 헤드셋인지 어떻게 감지합니까?Mac OS X에서 AudioUnit을 사용하여 스피커/헤드셋 감지
AudioUnit 및 kAudioUnitSubType_HALOutput을 사용하면 출력이 스피커 또는 헤드셋인지 어떻게 감지합니까?Mac OS X에서 AudioUnit을 사용하여 스피커/헤드셋 감지
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;
}