I want to make a program on the web which will capture an image via the user's webcam.
I am using the getUserMedia
Web API. Here is my code, but it does not work. How can I change it to capture the webcam image?
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
</script>
There is the JS:
var video = document.querySelector("#videoElement");
navigator.getUserMedia, elem = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
console.log(navigator.getUserMedia);
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true}, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
}
function videoError(e) {
// do something
}