简体   繁体   中英

How can I find the default audio device in Visual Basic .NET?

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM