How to detect a disconnected headphone jack in WinRT?

Is there a way to get a notification when the headphone jack is disconnected from the WinRT application? I want to be able to pause MediaElement when this happens to prevent sound from leaking through the speakers.

+4
source share
3 answers

Jack discovery notification is open through IMMNotificationClient :: OnDeviceStateChanged. Just by trying it on the win8 desktop, OnDeviceStateChanged is called with DEVICE_STATE_UNPLUGGED and DEVICE_STATE_ACTIVE when (un) connects the device. Unfortunately, this part of wasapi is documented as a desktop, so I think there is no way in WinRT to do this.

+3
source

Try the following:

Windows :: Devices :: List :: DeviceInformation :: CreateWatcher (Windows :: Devices :: List :: DeviceClass :: AudioRender);

This works on WinRT.

For more information about the method, see MSDN: http://msdn.microsoft.com/en-us/library/ie/windows.devices.enumeration.deviceinformation.createwatcher

+4
source

The only way this should be possible is through WASAPI, the Windows Audio Session API (see WASAPI sample ).

Unfortunately, WASAPI is not displayed in C #, only in C ++ (but I'm not sure if it covers socket detection or not. I honestly don't think that they detect connector detection at the API level ...).

Hoping for this help.

0
source

Source: https://habr.com/ru/post/1480648/


All Articles