Webcam doesn't play immediately on Chrome Beta for Android

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,

Never mind. I figured it out.

What did you need to do to get things going?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.