如何在javascript中关闭网络摄像头

时间:2016-08-07 07:02:09

标签: javascript

我有这个代码访问网络摄像头,我不知道如何在单击关闭按钮后停止网络摄像头。我怎么把它归还为假?

function camera() {
    var video = document.getElementById('video'),
    canvas = document.getElementById('canvas'),
    context = canvas.getContext('2d'),
    photo = document.getElementById('photo'),
    vendorUrl = window.URL || window.webkitURL;

    navigator.getMedia = navigator.getUserMedia ||
                     navigator.webkitGetUserMedia ||
                     navigator.mozGetUserMedia ||
                     navigator.msGetUserMedia;

    navigator.getMedia({
        video: true,
        audio: false,
        cornerRadius: 60
    }, function(stream){
        video.src = vendorUrl.createObjectURL(stream);
        video.play();
    }, function(error) {
        // An error occured
        // eror.code
    });

    document.getElementById('capture').addEventListener('click', function(){
        context.drawImage(video, 0, 0, 400, 300);
        photo.setAttribute('src', canvas.toDataURL('img/png'));
    });

}

0 个答案:

没有答案