2016-04-11 33 views
9

我想获取所有连接的麦克风的全名。我在Google上搜索一个答案,但没有答案让我满意。如何在C#中获取麦克风的全名?

让我告诉一些例子:

这些干将

1.

ManagementObjectSearcher mo = new ManagementObjectSearcher("select * from Win32_SoundDevice"); 

foreach (ManagementObject soundDevice in mo.Get()) 
{    
    MessageBox.Show(soundDevice.GetPropertyValue("Caption").ToString()); 
    // or 
    MessageBox.Show(soundDevice.GetPropertyValue("Description").ToString()); 
    //or 
    MessageBox.Show(soundDevice.GetPropertyValue("Manufacturer").ToString()); 
    //or 
    MessageBox.Show(soundDevice.GetPropertyValue("Name").ToString()); 
    //or 
    MessageBox.Show(soundDevice.GetPropertyValue("ProductName").ToString());      
} 

全表示: “设备的音频USB” 或 “设备与高清兼容的标准”。

2.

WaveInCapabilities[] devices = GetAvailableDevices();   
foreach(device in devices) 
{ 
    MessageBox.Show(device.ProductName); 
} 

了相同的答案: “设备的音频USB” 或 “设备与高清标准兼容”。

我想获取全名。我的意思是,诸如:“Sennheiser麦克风USB”。它甚至有可能吗?我发现:Get the full name of a waveIn device但它的一个链接被打破,我没有看到c#的任何dsound.lib(使用DirectSoundCaptureEnumerate)。 我错过了什么吗?或者还有其他的选择吗?

+2

设备的全名在Windows中是否可见*任意位置? (设备管理器等) – Heinzi

+0

@ Heinzi不,我没有在设备管理器中看到设备的全名。这是否意味着不可能做到? – Darooks

+0

那么,如果Windows不知道完整的设备名称,我不认为有办法检索它。 (但我不是Windows API的专家,所以如果有人能证明我错了,我会很高兴。) – Heinzi

回答

4

@AnkurTripathi的答案是正确的,但它返回一个包含多达32个字符的名称。如果任何人不想要这个限制,那么最好的办法是使用一个注射器:

using NAudio.CoreAudioApi; 

MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); 
var devices = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);    
foreach (var device in devices) 
    MessageBox.Show(device.friendlyName); 

它对我来说非常完美。

3

尝试n音讯https://naudio.codeplex.com/

for (int n = 0; n < WaveIn.DeviceCount; n++) 
{ 
    this.recordingDevices.Add(WaveIn.GetCapabilities(n).ProductName); 
    comboBoxAudio.Items.Add(WaveIn.GetCapabilities(n).ProductName); 
} 

为获得全名(的FriendlyName):

MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); 
foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active)) 
    { 
      this.recordingDevices.Add(device.FriendlyName); 
    } 
+0

与上面提到的答案相同。在这个例子中,ProductName只有31个字符。 – Darooks

+0

@Darooks设备的全名在Windows的任何位置都可以看到吗? - 如果没有 - 没有更多信息可用 – Cadburry

+0

@Cadburry我必须更换USB。现在在设备管理器中有全名。我以前没有注意到它。 – Darooks