gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 12:40:37 25 4
gpt4 key购买 nike

我想知道如何获取机器上已安装的音频输出设备 (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 DeviceConfigManagerErrorCode:0ConfigManagerUserConfig:FalseCreationClassName:Win32_SoundDeviceDescription:USB Audio DeviceDeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000DMABufferSize:ErrorCleared:ErrorDescription:InstallDate:LastErrorCode:Manufacturer:(Generic USB Audio)MPU401Address:Name:USB Audio DevicePNPDeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000PowerManagementCapabilities:PowerManagementSupported:FalseProductName:USB Audio DeviceStatus:OKStatusInfo:3SystemCreationClassName:Win32_ComputerSystemSystemName:Availability:Caption:Realtek AC'97 Audio for VIA (R) Audio ControllerConfigManagerErrorCode:0ConfigManagerUserConfig:FalseCreationClassName:Win32_SoundDeviceDescription:Realtek AC'97 Audio for VIA (R) Audio ControllerDeviceID:PCI\VEN_1106&DEV_3059&SUBSYS_09011558&REV_60\3&61AAA01&1&8DDMABufferSize:ErrorCleared:ErrorDescription:InstallDate:LastErrorCode:Manufacturer:RealtekMPU401Address:Name:Realtek AC'97 Audio for VIA (R) Audio ControllerPNPDeviceID:PCI\VEN_1106&DEV_3059&SUBSYS_09011558&REV_60\3&61AAA01&1&8DPowerManagementCapabilities:PowerManagementSupported:FalseProductName:Realtek AC'97 Audio for VIA (R) Audio ControllerStatus:OKStatusInfo:3SystemCreationClassName:Win32_ComputerSystemSystemName: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com