user1580348
user1580348

Reputation: 6051

Get automatically notified on audio device connection/disconnection?

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

Upvotes: 4

Views: 1609

Answers (2)

vicky
vicky

Reputation: 895

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

Upvotes: 1

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

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.

Upvotes: 3

Related Questions