Headphone Detection in Windows

I am trying to detect if the headphones are connected to Windows. I already tried DirectSound and the NAudio library and had no success. Anyone have any suggestions?

NOTE: this question is a duplicate of this question , but the answer to this question did not contain any code samples or tutorials.

+4
source share
2 answers

So ... I guess I could find something REALY obscure.

Can any of you check if this works? - You MUST have a NAudio link.

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 returns 1 (connected) or 0 (disconnected) .. and it works very well for me ..

UPDATE CodePlex app just published - iTunesHead

+1
source

What about Microsoft.DirectX.DirectSound.Speakers ?

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

  • Fivepointone
  • headphones
  • Mono
  • Quad
  • Sevenpointone
  • Stereo
  • Surround
-1
source

Source: https://habr.com/ru/post/1346399/


All Articles