I’m trying to get resources from a webcam element. Anything is looking good on PC. However, on Chrome Beta for Android, the webcam doesn’t play immediately after the function is fired. You have to click the button two times to make it play. How can I solve this? My code:
HTML
<video width=340></video>
<button id=button>Start</button>
JavaScript:
[code]var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame
, doc = document
, webcam = doc.querySelector(‘video’)
, button = doc.getElementById(‘button’)
;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia;
var playWebcam = function() {
navigator.getUserMedia(
constraints = {
audio: true,
video: true
},
function(stream) {
webcam.src = window.URL.createObjectURL(stream);
webcam.play();
},
function(err) {
console.log(err);
}
);
};
button.addEventListener(‘click’, function() {
playWebcam();
}, false);[/code]
Thanks,