c# - 如何在 C# 中枚举音频输出设备

标签 c# windows

我想知道如何获取机器上已安装的音频输出设备 (waveOut) 的列表

操作系统:Windows(XP、Vista、7) 框架:.Net 3.5 语言:c#

在遍历此列表时,我想获取标识符、制造商等信息……每个设备。

有什么提示吗?

最佳答案

这是使用 WMI(引用 System.Management)在 C# 中枚举音频设备的代码。

    ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
           "SELECT * FROM Win32_SoundDevice");

    ManagementObjectCollection objCollection = objSearcher.Get();

    foreach (ManagementObject obj in objCollection)
    {
        foreach (PropertyData property in obj.Properties)
        {
            Console.Out.WriteLine(String.Format("{0}:{1}", property.Name, property.Value));
        }
    }

这导致输出如下:

Availability:
Caption:USB Audio Device
ConfigManagerErrorCode:0
ConfigManagerUserConfig:False
CreationClassName:Win32_SoundDevice
Description:USB Audio Device
DeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000
DMABufferSize:
ErrorCleared:
ErrorDescription:
InstallDate:
LastErrorCode:
Manufacturer:(Generic USB Audio)
MPU401Address:
Name:USB Audio Device
PNPDeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000
PowerManagementCapabilities:
PowerManagementSupported:False
ProductName:USB Audio Device
Status:OK
StatusInfo:3
SystemCreationClassName:Win32_ComputerSystem
SystemName:
Availability:

Caption:Realtek AC'97 Audio for VIA (R) Audio Controller
ConfigManagerErrorCode:0
ConfigManagerUserConfig:False
CreationClassName:Win32_SoundDevice
Description:Realtek AC'97 Audio for VIA (R) Audio Controller
DeviceID:PCI\VEN_1106&DEV_3059&SUBSYS_09011558&REV_60\3&61AAA01&1&8D
DMABufferSize:
ErrorCleared:
ErrorDescription:
InstallDate:
LastErrorCode:
Manufacturer:Realtek
MPU401Address:
Name:Realtek AC'97 Audio for VIA (R) Audio Controller
PNPDeviceID:PCI\VEN_1106&DEV_3059&SUBSYS_09011558&REV_60\3&61AAA01&1&8D
PowerManagementCapabilities:
PowerManagementSupported:False
ProductName:Realtek AC'97 Audio for VIA (R) Audio Controller
Status:OK
StatusInfo:3
SystemCreationClassName:Win32_ComputerSystem
SystemName:
Availability:

WMI annoyingly does not appear to distinguish simply between input and output devices for audio. However, using the managed interface to DirectSound, and the DevicesCollection class, as below (reference Microsoft.DirectX.DirectSound), we can get a lot more sound-oriented information.

        DevicesCollection devColl = new DevicesCollection();
        foreach (DeviceInformation devInfo in devColl)
        {
            Device dev = new Device(devInfo.DriverGuid);   

            //use dev.Caps, devInfo to access a fair bit of info about the sound device
        }

关于c# - 如何在 C# 中枚举音频输出设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1525320/

相关文章:

c# - 将第一个 child 与 linq dynamic 进行比较

c# - IEnumerable.Except() 和自定义比较器

c# - 集合中集合的 Where 子句

c# - 有没有更好的方法来测量 CPU 性能而不影响性能?

windows - 如何识别具有以编程方式可见和最小化的未显示窗口的 Windows 10 后台存储进程?

c - Windows:使用事件进行共享内存同步

c# - C# 应用程序中的命令行界面

c# - 密码验证的正则表达式 C#

c++ - 为什么我用 WriteFile 写入 0 个字节?

c++ - STL std::map 的 MFC 等价物