我試圖從網絡攝像頭捕捉視頻/照片。我已經創建了一個腳本,但我只想在點擊按鈕時啓動攝像頭訪問。有了這個腳本,它將立即開始(我不想)。我怎樣才能綁定這個事件點擊請?getUserMedia on click
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("video"),
videoObj = { "video": true },
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
// Put video listeners into place
if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
// Trigger photo take
document.getElementById("snap").addEventListener("click", function() {
context.drawImage(video, 0, 0, 487, 365);
});
}, false);
你有一些很好的幫助 - 應該可以標記答案,給予幫手點。 – sandover