Detect if headphones are plugged in or not via C#

后端 未结 3 1545
不知归路
不知归路 2020-12-02 21:53

There is no example how to detect if headphones are plugged in or not via C#.

I assume should be some event for that...

Does make sense to use WMI?



        
3条回答
  •  广开言路
    2020-12-02 22:18

    Detecting changes of this kind is possible by using the IMMDeviceEnumerator::RegisterEndpointNotificationCallback method.

    As you want to handle this in C# you will need a managed wrapper which has already been implemented by Akos Mattiassich. You can find a thourough example here: Managed Wrapper around MMAudioDeviceApi

    He states:

    The program can play test sound on selected devices and it updates the list automatically on changes eg. through the control panel or in case of plugging new device physically.

提交回复
热议问题