jhuckaby / webcamjs

HTML5 Webcam Image Capture Library with Flash Fallback
MIT License
2.5k stars 1.11k forks source link

How to force mobile devices to use the rear camera... #231

Closed nbulian closed 7 years ago

nbulian commented 7 years ago

Hi! Aweson work!

I'm using your library and I want to know if is there a way to use the rear camera in mobile devices?

Thanks!

jhuckaby commented 7 years ago

Hi there, thanks!

Check out this document on MDN, it describes how to set the rear camera using a constraint: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia

You can pass this to WebcamJS along with the width and height:

Webcam.set( 'constraints', {
    width: 1280,
    height: 720,
    facingMode: { exact: "environment" }
} );

More about constraints in the docs here: https://github.com/jhuckaby/webcamjs/blob/master/DOCS.md#custom-user-media-constraints-advanced

Note that this does not work with Adobe Flash fallback -- it only works on browsers that support native HTML5 getUserMedia.

- Joe