使用getUserMedia后关闭网络摄像头/相机 [英] Turn off webcam/camera after using getUserMedia

查看:152
本文介绍了使用getUserMedia后关闭网络摄像头/相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Chrome扩展程序,该扩展程序使用后台页面访问用户的网络摄像头.

I'm developing a Chrome Extension that uses the background page to access the user's webcam.

用户可以选择关闭相机.

Users are given the option to turn the camera off.

该流似乎已关闭.相关功能不再接收流.但是,摄像头指示灯(当前正在Macbook pro上进行开发和测试)无法关闭.

The stream appears to be being turned off. The relevant functions are no longer receiving the stream. However the webcam light (currently being developed and tested on a mac book pro) does not turn off.

有什么想法吗?

这是我设置流的代码:

if (navigator.webkitGetUserMedia!=null) {

    var options = { 
        video:true, 
        audio:false 
    };  
    navigator.webkitGetUserMedia(options, 
        function(stream) { 
        vid.src = window.webkitURL.createObjectURL(stream);
        localstream = stream;
        vid.play();
        console.log("streaming");
    }, 
        function(e) { 
        console.log("background error : " + e);
        }); 
} 

这是我关闭流的方法:

function vidOff() {
    clearInterval(theDrawLoop);
    ExtensionData.vidStatus = 'off';
    vid.pause();
    vid.src = "";
    localstream.stop();
    DB_save();
    console.log("Vid off");
}

有明显的我想念吗?

推荐答案

上面的代码有效-如@jib 此处使用上面的代码:

The code above works - as shown by @jib here using the above code:

function vidOff() {
    vid.pause();
    vid.src = "";
    localstream.stop();
}

问题在于它是一个持久的后台页面.我要换用事件页面,以解决Chrome扩展程序.

The problem is to do with it being a persistent background page. I'm swapping over to event pages for the Chrome extension as a work around.

这篇关于使用getUserMedia后关闭网络摄像头/相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆