C# 如何在Windows中连接媒体设备
我将准备一个应用程序竖琴,询问用户他们想使用哪个网络摄像头,并从选定的网络摄像头中获取流。要做到这一点,我需要搜索并找到连接到计算机的网络摄像头。这是我的第一步。第二步是从网络摄像头中获取流。如何才能做到这一点?您可以使用此代码-基于ManagementObjectSearcher类C# 如何在Windows中连接媒体设备,c#,.net,webcam,C#,.net,Webcam,我将准备一个应用程序竖琴,询问用户他们想使用哪个网络摄像头,并从选定的网络摄像头中获取流。要做到这一点,我需要搜索并找到连接到计算机的网络摄像头。这是我的第一步。第二步是从网络摄像头中获取流。如何才能做到这一点?您可以使用此代码-基于ManagementObjectSearcher类 选择*对性能有很大影响。请改用Win32_USBHub中的Select DeviceID、PNPDeviceID、Description。 static List<USBDeviceInfo> GetU
选择*对性能有很大影响。请改用Win32_USBHub中的Select DeviceID、PNPDeviceID、Description。
static List<USBDeviceInfo> GetUSBDevices()
{
List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
collection = searcher.Get();
foreach (var device in collection)
{
devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
(string)device.GetPropertyValue("Description")
));
}
collection.Dispose();
return devices;
}