gpt4 book ai didi

javascript - jQuery 网络摄像头/闪光灯 : How to detect if webcam is active?

转载 作者:搜寻专家 更新时间:2023-11-01 04:19:26 25 4
gpt4 key购买 nike

我正在使用 this jQuery webcam plugin在我正在处理的网站上。如果您访问该网站,您会注意到它使用了 Flash,您必须单击“接受”才能使其正常工作。

我想确定网络摄像头是否处于事件状态(打开)。我如何使用 javascript/jquery 执行此操作?

换句话说,我在这里的 if 语句中替换了什么?

function capture_image(){
if(webcam.muted == true) {alert("hey");}

我远不是 javascript 和 jquery 的专家,所以真正的代码将不胜感激。

此外,如果有人能告诉我如何捕获网络摄像头被激活的事件,也将不胜感激。如果您无法弄清楚,请不要担心。

最佳答案

在网络摄像头的debug选项中添加如下函数。

$("#camera").webcam({
width: 320,
// other options etc.
debug: function(type, message) {
if (message === "Camera started") { window.webcam.started = true; }
}
});

我们无法测试不活动是否为真(即 muted === true)但现在我们可以测试 webcam.startedtrueundefined/false:

function capture_image(){
if( !webcam.started ) { alert("hey, camera not started"); }
}

如何捕捉事件

除了 debug 事件之外,本身没有事件。你可以做一个...

首先执行以下操作:

$("#camera").webcam({
width: 320,
// other options etc.
debug: function(type, string) {
if (string === "Camera started") {
window.webcam.started = true;
if (window.webcam.onStarted) { window.webcam.onStarted(); }
}
}
});

接下来向我们的新事件 webcam.onStarted 添加一个函数:

window.webcam.onStarted = function () {
alert("Whey, the webcam started");
};

关于javascript - jQuery 网络摄像头/闪光灯 : How to detect if webcam is active?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10592738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com