02 Oct

Accessing the device camera using HTML5 GetUserMedia

Download complete source file here.

Primarily here’s the code that does that:

navigator.mediaDevices.getUserMedia

which takes a “contstraints” object as an argument which at the minimum looks like this:

var constraints = { audio: false, video: true }

videoElem is a <video> element on the page.

For simplicity reasons, I haven’t written this code to fail gracefully or support older browsers which may support a slightly different syntax. This is something to consider when you may be using this for something serious.