Is it possible to get automatically notified whenever the user connects or disconnects an audio device?
-
1If you meant un/plugging USB-based audio device, then yes. Use `WM_DEVICECHANGE` window message. – Jay Oct 15 '12 at 19:00
-
http://stackoverflow.com/q/861601/10396 may have some useful info. – AShelly Oct 15 '12 at 19:43
-
Jay: I fear, that when using WM_DEVICECHANGE, this could exclude audio devices using another interface. – user1580348 Oct 15 '12 at 22:08
2 Answers
In Vista+ you can use Core Audio IMMNotificationClient interface to be notified.
The IMMNotificationClient interface provides notifications when an audio endpoint device is added or removed, when the state or properties of an endpoint device change, or when there is a change in the default role assigned to an endpoint device.
Handling WM_DEVICECHANGE
and/or polling is the solution in odler OS versions.

- 68,205
- 6
- 94
- 158
-
1Thanks for the help so far! Does anybody know how to implement the IMMNotificationClient interface in Delphi, to be notified when audio devices are connected or disconnected? Thank you! – user1580348 Oct 15 '12 at 22:05
-
The MSDN article explains it step by step, and conversion to Delphi - as far as I know - is rather straightforward. You create enumerator, register for notifications and eventually receive them. – Roman R. Oct 16 '12 at 06:16
To receive notifications for Audio Devices plug and unplug, please follow these steps:
Derive class from IMMNotificationClient interface using this msdn link: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370810%28v=vs.85%29.aspx
Create Device Enumeration Object using this msdn link: http://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/610aacff-062e-4453-8437-01f0de038b07/jack-detection-for-headset
In the 2nd step repalce line IMMNotificationClient *pNotify = NULL;
with IMMNotificationClient *pNotify = new CMMNotificationClient;
With this implementation all you will receive all plug, unplug notification in CMMNotificationClient's overloaded functions.
Please make sure to delete CMMNotificationClient at end :)

- 885
- 1
- 7
- 23