Question

Is there a way to get notified whenever a headphone jack is unplugged in a WinRT app? I want to be able to pause MediaElement playback when it happens to prevent the sound from leaking out through loudspeakers.

Was it helpful?

Solution 2

Jack detection notification is exposed through IMMNotificationClient::OnDeviceStateChanged. Just tried it on win8 desktop, OnDeviceStateChanged gets called with DEVICE_STATE_UNPLUGGED and DEVICE_STATE_ACTIVE when (un)plugging a device. Sadly that part of wasapi is documented as desktop only so i guess there's no way to do it in WinRT.

OTHER TIPS

Try the following:

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

This works on WinRT.

See MSDN for more detail on the method: http://msdn.microsoft.com/en-us/library/ie/windows.devices.enumeration.deviceinformation.createwatcher

The only way it should be possible is through WASAPI - Windows Audio Session API (see WASAPI sample).

Sadly, WASAPI isn't exposed in c#, only in C++ (but I'm not sure if it covers jack detection or not. I honestly don't believe that they expose jack detection at the API level...).

Hopes this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top