Detect headphones in Windows [duplicate]
Asked Answered
A

2

5

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.

Adorl answered 3/4, 2011 at 1:33 Comment(5)
Duplicate of this question: #862101 That question isn't tagged for Windows, but Larry Osterman is a Microsoft software engineer who's worked on the audio subsystem for years so he knows what he's talking about. He doesn't reference any samples or tutorials of how to do this, so I'm still interested to see if anybody digs anything up in response to this question.Raouf
please pardon my edit of your question, but I wanted to make sure it isn't closed as a duplicate.Raouf
Are you trying to detect analog headphones plugged into the line-out jack of a soundcard or USB headphones? That will heavily influence my answer.Needlefish
@selbie: only analog.. But I think I find the answer..Adorl
Take a look here #33873395Flicker
A
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

Adorl answered 3/4, 2011 at 3:57 Comment(2)
I have tried running this project on my PC and that particular GUID does not seem to exist (Null reference), so I think it depends on hardware/drivers. I also tried comparing all the device properties before/after plugging and unplugging headphones and nothing changes.Coker
Yeah..that was what I was thinking when I found this GUID, must be a thing only on my Dell, so I kinda drop this project after that..Adorl
W
-1

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
Wilks answered 3/4, 2011 at 2:5 Comment(2)
All the prop's retun the same value. I keep plugging/unplugging the headphones, all stay the same.. HeadPhone: False FivePointOne: False Mono: False Quad: False SevenPointOne: False Stereo: True Surround: FalseAdorl
Only other refs I could find are: <mp3car.com/coders-corner/88344-windows-speaker-setup.html> and <codeproject.com/KB/audio-video/DirectSound9p1.aspx>Wilks

© 2022 - 2024 — McMap. All rights reserved.