我如何获得可用声音设备的列表?我的意思是该图片中的内容。
我想要它在组合框中。我的意思是:
- 麦克风
- 立体声混音
- 在线
- ..等等..
但一定是因为系统根据语言本地化系统更改了设备的名称,而这正是我所需要的。
例如,在我的语言中,麦克风称为 Mikrofon 和 Stereo Mix = Směšovač stereo
我需要获取这些设备名称,仅此而已
可以制作示例代码吗?
最佳答案
这是做我需要的..
[DllImport("winmm.dll", SetLastError = true)]
static extern uint waveInGetNumDevs();
[DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern uint waveInGetDevCaps(uint hwo, ref WAVEOUTCAPS pwoc, uint cbwoc);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct WAVEOUTCAPS
{
public ushort wMid;
public ushort wPid;
public uint vDriverVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szPname;
public uint dwFormats;
public ushort wChannels;
public ushort wReserved1;
public uint dwSupport;
}
public static string[] GetSoundDevices()
{
uint devices = waveInGetNumDevs();
string[] result = new string[devices];
WAVEOUTCAPS caps = new WAVEOUTCAPS();
using (StreamWriter sw = new StreamWriter("appdata/audio/name"))
{
for (uint i = 0; i < devices; i++)
{
waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
result[i] = caps.szPname;
sw.WriteLine(caps.szPname);
}
return result;
}
}
.. 但是每一行都被缩短了,我无法全部写完。
如何修改列出整体名称的代码?
谢谢!
关于c# - C# 中的捕获设备列表(例如麦克风、立体声混音...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29936641/