获取音频设备的列表,并使用C#选择一个 [英] Get list of audio devices and select one using c#
问题描述
我在Windows中使用C#创建基于桌面应用程序。
Hi I am creating a desktop based application in windows using C#.
我要显示所有可用的音频功放和名单;在2个不同的组合框视频设备。
从组合框中选择的任何设备将设置特定的设备作为默认的
I have to show list of all available audio & video devices in 2 different combo boxes. Selecting any device from combo box will set that particular device as the default one
我使用WMI。
code来获得可用的音频设备列表:
Code to get list of available audio devices:
ManagementObjectSearcher mo =
new ManagementObjectSearcher("select * from Win32_SoundDevice");
foreach (ManagementObject soundDevice in mo.Get())
{
String deviceId = soundDevice.GetPropertyValue("DeviceId").ToString();
String name = soundDevice.GetPropertyValue("Name").ToString();
//saving the name and device id in array
}
如果我尝试设置设备是这样的:
if i try to set the device like this:
using (RegistryKey audioDeviceKey =
Registry.LocalMachine.OpenSubKey(audioDevicesReg
+ @"\" + audioDeviceList.SelectedText.ToString(), true)){}
我得到异常:
System.Security.SecurityException occurred in mscorlib.dll
现在我有几个问题:
1) How to set the selected device as the default audio device?
2) The array contains device name as : "High Definition audio device"
even when I have attached a headset.
3) I want the list as speaker,headset etc...How to get that?
任何人可以点我在正确的方向?
can anybody point me in the right direction?
推荐答案
最后我做到了,我得到的音频设备列表:
Finally i did it i got a list of audio devices:
我也跟着这样的:
的http://www.koders.com/info.aspx?c=ProjectInfo&pid=KP5SPVLW8SCWPZF74272GM3NBD
但还是视频设备的名单仍然找到
感谢ü拉里
but still list of video devices is still to find thank u Larry
更新:
有关视频设备列表,并调用摄像头我想这个链接:
http://www.c-sharpcorner.com/UploadFile/yougerthen/810262008070218AM /8.aspx
for video devices list and invoke camera i tried this link: http://www.c-sharpcorner.com/UploadFile/yougerthen/810262008070218AM/8.aspx
我得到的连接的相机列表中,但视频捕获只有一次或系统重新启动后两次
i got the list of cameras attached but video is captured only once or twice after system reboot
这篇关于获取音频设备的列表,并使用C#选择一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!