问题描述
有没有比如如何检测是否插入耳机,或不通过C#堵塞。
There is no example how to detect if headphones are plugged in or not via C#.
我想应该是一些事件......
I assume should be some event for that...
有一定道理使用WMI?
Does make sense to use WMI?
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\cimv2",
"SELECT * FROM Win32_SoundDevice");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_SoundDevice instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("StatusInfo: {0}", queryObj["StatusInfo"]);
}
会有人如此高兴规定的?
Would anyone be so pleased to provide it?
感谢您!
推荐答案
检测这种变化是可以通过使用的方法。
Detecting changes of this kind is possible by using the IMMDeviceEnumerator::RegisterEndpointNotificationCallback method.
当你要处理这在C#中,您将需要它已经被阿科什Mattiassich实现的托管包装。你可以在这里找到一个thourough例如:
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
他说:
该程序可以在选定的设备和它玩测试声音自动更新上的变化如表。通过控制面板或在物理上插入新的设备的情况下。
这篇关于检测是否插入耳机,或不通过C#堵塞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!