How to detect unplugged headphone jack in WinRT?

£可爱£侵袭症+ 提交于 2019-12-05 16:21:49

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.

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.

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