I have a plugin where in I capture Image using Web camera present on the laptop or mobile and then place it in the canvas. All this works well in Chrome but when using Firefox , it simply doesn't work. I suspect its the navigator.getUserMedia which is causing the problem in firefox as it is deprecated.
link : https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia
And Google developer suggests the use of navigator.getUserMedia and it is also compatible with my app.
link: https://developers.google.com/web/updates/2015/10/media-devices
So please do suggest what changes should be done in the below code for it to work in firefox.
Thanks in Advance.
<script type="text/javascript">
var ctx = null;
var canvas = document.getElementById("tmpImage");
var localMediaStream = null;
var video = document.querySelector('video');
function snapshot() {
if (localMediaStream) {
ctx.drawImage(video, 0, 0);
var img = document.getElementById('CaptureImage');
// "image/webp" works in Chrome 18. In other browsers, this will fall back to image/png.
img.src = canvas.toDataURL('image/webp');
}
}
function hasGetUserMedia() {
// Note: Opera builds are unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
function onFailSoHard(e) {
if (e.code == 1) {
alert('User denied access to their camera');
} else {
alert('getUserMedia() not supported in your browser.');
}
}
function start() {
if (hasGetUserMedia()) {
if (navigator.webkitGetUserMedia)
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
//var getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;
//var gumOptions = { video: true, toString: function () { return 'video'; } };
if (navigator.getUserMedia) {
navigator.getUserMedia({
video: true,
audio: false
}, function (stream) {
if (navigator.webkitGetUserMedia) {
video.src = window.webkitURL.createObjectURL(stream);
} else {
video.src = stream; // Opera
}
localMediaStream = stream;
}, onFailSoHard);
} else {
video.src = 'somevideo.webm'; // fallback.
}
}
}
function stop() {
video.pause();
video = document.getElementById('sourcevid');
video.src = "";
localMediaStream.stop();
}
function ResizeCanvas() {
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
}
$(document).ready(function () {
ctx = canvas.getContext('2d');
});