开发者

Detecting arrival/disconnection of audio device

开发者 https://www.devze.com 2023-02-01 05:05 出处:网络
I would like to add feature to my app that will allow detecting arrival and disconnection of playback/capture devices on Windows OS. Like in Skype - when you unplug the device - it show notification t

I would like to add feature to my app that will allow detecting arrival and disconnection of playback/capture devices on Windows OS. Like in Skype - when you unplug the device - it show notification that device is lost and e.g. asks you to choose another one.

I'm using DirectSound. I think there can be two ways of solving this problem.

  1. In a separate thread call EnumerateDevices callback and manually detect changes.
  2. Somehow handle WM_DEVICECHANGE message. But AFAIK WM_DEVICECHANGE has some limitations. Btw, It doesn't work with the "sma开发者_开发问答rt" audio cards - that allow plugging any kind of device into any sink. If I disable device in device manager - WM_DEVICHANGE arrives. If I manualy unplug my headphones jack - nothing happens. But I need to handle such situation.

Please, advice the proper approach.

Thanks in advance.


You can register for add/remove audio device notifications in Windows Vista and newer using Core Audio SDK

IMMDeviceEnumerator::RegisterEndpointNotificationCallback

See http://msdn.microsoft.com/en-us/library/windows/desktop/dd371403(v=vs.85).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消