Detect headphones in Windows [duplicate]

拈花ヽ惹草 提交于 2019-11-27 03:06:00

问题


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?

NOTE: this question is a duplicate of this question, but the answer to that question didn't contain any code samples or tutorials.


回答1:


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());

This property return's 1 (Plugged) or 0 (Unplugged).. and It's working realy good for me..

UPDATE: Just published the app on CodePlex - iTunesHead




回答2:


What about Microsoft.DirectX.DirectSound.Speakers?

A Speakers object should have one of the following speaker type properties set to true:

  • FivePointOne
  • Headphone
  • Mono
  • Quad
  • SevenPointOne
  • Stereo
  • Surround


来源:https://stackoverflow.com/questions/5526998/detect-headphones-in-windows

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