i want to access my webcam with getUserMedia in javascript.
var video = document.querySelector("#webcam");
// ask permission
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
// if the user allowing
if (navigator.getUserMedia) {
navigator.getUserMedia({
video: true
}, handleVideo, videoError);
}
// this function will executed when the user allowing the permission
function handleVideo(stream) {
video.srcObject = stream;
}
// this function will executed when the user block the permission
function videoError(e) {
// do something
alert("error")
}
<video id="webcam" autoplay="true"></video>
when i allowing the permission, it show the error alert. and i'm using https. does anyone can help me ? any answer would be appreciated it. thanks in advance