Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect when headphones are plugged in, and unplugged? [duplicate]

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.

like image 383
Izzy Rodriguez Avatar asked Dec 20 '25 18:12

Izzy Rodriguez


1 Answers

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

like image 91
Izzy Rodriguez Avatar answered Dec 22 '25 08:12

Izzy Rodriguez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!