Detecting arrival/disconnection of audio device
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.
- In a separate thread call EnumerateDevices callback and manually detect changes.
- 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
精彩评论