webcam video not rendered in web page

Viewed 76

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

1 Answers

Are you sure your webcam is activated in the computer? On windows in can be necessary to autorize access to the microphone to be start video.

Related