0

This needs to be able to work for the last two or three Windows versions (7, Vista, and probably XP). In Visual Basic .NET, how can I find the default audio device (I'm looking for speakers and stuff, not mics). Thanks!

EDIT: Guys, I am really walking into unfamiliar territory here. It seems like every time I try to use a code sample, there are build errors that could not be more cryptic and involve the errors occurring inside of libraries and all sorts of stuff like that. Is there anything for a total beginner to learn how to do this? Thanks!

Panzercrisis
  • 4,590
  • 6
  • 46
  • 85
  • What have you tried? Try reading this question: http://stackoverflow.com/questions/1809190/how-to-identify-the-default-audio-devices-from-a-net-application – Security Hound Mar 19 '12 at 14:12
  • I've been trying pretty much exactly that, but any references to it are kind of vague, so I haven't been able to apply it. – Panzercrisis Mar 19 '12 at 14:13

2 Answers2

2

There are a few audio APIs in Windows, and all of them offer device enumeration. The recent "main" API is Vista+ only, so you need to decide if XP support is important.

Vista+ enumeration: Enumerating Audio Devices

Code good for all Windows versions: Sample: how to enumerate waveIn and waveOut devices on your system

Those are C++ code links above, in VB.NET you will need P/Invoke calls or a wrapper library, such as NAudio to take care of inner details.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • I keep getting linker errors on that one, such as: Error 1 error LNK2019: unresolved external symbol __imp__waveOutGetDevCapsW@12 referenced in function _wmain f.obj – Panzercrisis Mar 19 '12 at 14:41
  • You are not going to go far stumbling on every simple C++ thing. Why don't you check out .NET code based on `NAudio` library instead? So close to your question: http://stackoverflow.com/questions/1449136/enumerate-recording-devices-in-naudio – Roman R. Mar 19 '12 at 15:07
  • Thanks for all your help on everything yesterday, Roman. I was having to try to do something with the registries that was apparently impossible in Windows, and combine that with the fact that I was basically inexperienced in programming directly with regards to Windows, and I really wasn't sure what I was doing at all. Thanks, man. – Panzercrisis Mar 20 '12 at 16:27
0

Some audio APIs (winMM, DirectSound, DirectShow, Media Foundation, WASAPI) allow you to enumerate devices, but offer a default; some (Beep, PlaySound) only allow playing via the default device.

The simplest API to start with is PlaySound (well, except perhaps Beep, but that is of limited usefulness.) What are you trying to play? That will help determine the choice of the API to use.

Maurits
  • 26
  • 1