我想知道如何获取机器上已安装的音频输出设备 (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/