c# - 在 C# 中获取网络摄像头的当前状态
问题描述
我试图弄清楚如何检查网络摄像头/视频捕获设备是否已被另一个应用程序使用而不实际激活它。
我目前的方法是使用 AForge.NET 库并使用 VideoCaptureDevice 对象的 .IsRunning 属性,如下所示:
var videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo videoDevice in videoDevices)
{
VideoCaptureDevice camera new AForge.Video.DirectShow.VideoCaptureDevice(videoDevice.MonikerString);
Debug.Print(camera.IsRunning)
}
我猜 IsRunning 属性仅适用于已使用该库启动的 VideoCaptureDevices,我需要对设备进行较低级别的 DirectShow 访问。
虽然在 C# 中使用 DirectShow 有很多方法,但即使在 C++ 中使用 DirectShow,我也无法找到检查状态的方法。我需要在这里表演一些魔法吗?
谢谢
托拜厄斯·廷佩
解决方案
我不完全确定这是否对您有帮助,但我找到了您的问题,因为我想编写一个自定义应用程序来控制我的忙灯。这是非常“在我的机器上工作”认证的 - 这不是试图给出一般性答案。但是,我认为它可能会对您有所帮助,并且可能是下一个在谷歌搜索时遇到此页面的人......
private static bool IsWebCamInUse()
{
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam\NonPackaged"))
{
foreach (var subKeyName in key.GetSubKeyNames())
{
using (var subKey = key.OpenSubKey(subKeyName))
{
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
{
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long) subKey.GetValue("LastUsedTimeStop") : -1;
if (endTime <= 0)
{
return true;
}
}
}
}
}
return false;
}
推荐阅读
- python - Python Kivy:ScrollView 在 FloatLayout 中不可滚动
- c# - 在标签 C# 中显示 Json 变量
- ios - Apple Silicon M1 上的 React Native - 链接库“libPods-ProjectName.a”缺少此目标所需的一个或多个架构:x86_64
- php - Laravel 迁移 - 一般错误:1215 无法添加外键约束
- html - 悬停状态前和变换比例后图像模糊
- parameters - 如何在 ADF 中获取 Azure 订阅和租户
- python-3.x - 在 SQLAlchemy 中关闭会话
- javascript - document.querySelectorAll() 的 TS-lint 错误
- excel - Excel - 我们如何使用 LAMBDA() 替换单元格中的多个字符或整个单词
- python - 使用 if 语句在 Python 中使用 Turtle 匹配 x/y 坐标