xxxxxxxxxx
// function getWebCapVideo() that will take an # as parameter
function getWebCapVideo(id) {
// grab webcam video and display it in the video element
navigator.mediaDevices
.getUserMedia({ video: true })
.then(function (stream) {
var video = document.querySelector(id);
video.srcObject = stream;
video.onloadedmetadata = function (e) {
video.play();
};
})
.catch(function (err) {
console.log("An error occurred: " + err);
});
}
// use
getWebCapVideo("#cameraPreview");