4

Is it possible to get automatically notified whenever the user connects or disconnects an audio device?

user1580348
  • 5,721
  • 4
  • 43
  • 105

2 Answers2

3

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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • 1
    Thanks 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
1

To receive notifications for Audio Devices plug and unplug, please follow these steps:

  1. Derive class from IMMNotificationClient interface using this msdn link: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370810%28v=vs.85%29.aspx

  2. 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 :)

vicky
  • 885
  • 1
  • 7
  • 23