简体   繁体   中英

Get the name of the sound devices in C#

I need to get the names of a computer sound drivers. Put it in a list or string. All that I found was a "int" return methods of the "winmm.dll", like "waveInGetDevCapsA" and "waveInGetDevCapsW".

Any sugestion?

If you want to enumerate audio devices, it becomes very easy by using SlimDX . It requires DirectX to be installed in the computer though.

For example, to enumerate the audio capture devices:

 DeviceCollection coll = DirectSoundCapture.GetDevices();
 foreach( DeviceInformation dev in coll ) {
    ...

 }

To enumerate audio playback devices:

DeviceCollection coll = DirectSound.GetDevices();
   foreach( DeviceInformation di in coll ) {

   }

The DeviceInformation class has a Description property of type string . It also has a DriverGuid property of type Guid that enables you to "select" the device to perform either audio capture or playback (that can also be done by means of SlimDX).

EDIT: a method using Winmm.dll Please take a look at the following entry in Code Project. It builds an enumerator using Winmm.dll only.

Hope this helps!

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