【问题标题】:How to detect when an Audio Device is disconnected in CoreAudio?如何在 CoreAudio 中检测音频设备何时断开连接?
【发布时间】:2014-04-28 20:40:31
【问题描述】:
【问题讨论】:
标签:
macos
core-audio
device
【解决方案1】:
我想通了!只需将侦听器添加到适当的 AudioDeviceID(您要监控的设备):
// add listener for detecting when a device is removed
const AudioObjectPropertyAddress alive_address =
{
kAudioDevicePropertyDeviceIsAlive,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
AudioObjectAddPropertyListener(current_device_id_, &alive_address, deviceIsAliveCallback, &player_);
然后编写相应的回调:
OSStatus deviceIsAliveCallback(AudioObjectID inObjectID,
UInt32 inNumberAddresses,
const AudioObjectPropertyAddress inAddresses[],
void* inClientData)
{
// your code here
}
希望这对某人有所帮助!