问题描述
我想检测是否插入耳机在Windows上。我已经试过了DirectSound和n音讯库并没有成功。有没有人有什么建议?
I'm trying to detect if the headphones are plugged in on Windows. I've already tried DirectSound and the NAudio library and have not had any success. Does anyone have any suggestions?
请注意:这个问题是这个问题,但这个问题的答案不包含任何code样品或教程。
NOTE: this question is a duplicate of this question, but the answer to that question didn't contain any code samples or tutorials.
推荐答案
所以...我想我可能发现了一些晦涩REALY ..
So...I think I might found something REALY obscure..
可以任意你们的检查其是否正常工作? - 必须在 引用库..
Can any of you guys check if that works? - You MUST have the NAudio library referenced..
var enumerator = new MMDeviceEnumerator();
var d = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
Console.WriteLine(d.Properties[new Guid("46d16a2c-5654-41c0-911e-7860d2bce7ee")].Value.ToString());
这返还财产的1(插入式)或0(不插电)..和它的工作对我真的很好。
This property return's 1 (Plugged) or 0 (Unplugged).. and It's working realy good for me..
更新:刚刚发布的应用程序在 codePLEX - iTunesHead 一>
UPDATE: Just published the app on CodePlex - iTunesHead
这篇关于检测耳机在Windows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!