我有这个代码访问网络摄像头,我不知道如何在单击关闭按钮后停止网络摄像头。我怎么把它归还为假?
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'));
});
}