Get automatically notified on audio device connection/disconnection?

与世无争的帅哥 提交于 2019-12-13 15:11:15

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/12899658/get-automatically-notified-on-audio-device-connection-disconnection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!