问题
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