Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable rear camera with HTML5

I'm working on a project with MVC ASP.Net 4 HTML5 (default browser is google-chrome v29.0.1547.57) I can interact with these tools and take photographs but only with front camera, How I could enable rear camera? the characteristic of the Tablet: Samsung Galaxy Tab 2 I hope you can help me

like image 831
raranibar Avatar asked Sep 04 '13 22:09

raranibar


People also ask

How do you access camera in JavaScript?

To access a camera from a browser with JavaScript, we can use the WebRTC API to access the camera when permission is granted. To do this, we write: const video = document. createElement("video"); video.

How to get camera and video control with HTML5?

Camera and Video Control with HTML5. The method for getting access to camera was initially navigator.getUserMedianavigator.mediaDevices.getUserMedia. Browser vendors have recently ruled that getUserMedia should only work on https: protocol. You'll need a SSL certificate for this API to work.

How to make the browser use the front-facing camera on devices?

To tell the browser to make use of the front or back (on mobile) camera on devices, you can specify a facingMode property in the video object: This setting will make use of the front-facing camera at all times in all devices.

Is there any way to access Opera 12 camera using HTML5?

It seems that Opera 12 does not support using Camera. Is there any way to access camera by using HTML5? I've just recently started working with a tool called Bridgeit. This is a combination of javascript in the browser and an app on the phone. It seems to work pretty well so far.

How do I connect my camera/webcam to the browser?

Once it's been established that the browser supports navigator.mediaDevices.getUserMedia, a simple method sets the video element's src to the user's live camera/webcam. Calling the play method of the video then starts the element's live streaming video connection. That's all that's required to connect your camera to the browser!


2 Answers

Check out https://simpl.info/getusermedia/sources/ that shows how you can select sources using

MediaStreamTrack.getSources(gotSources); 

You can then select the source and pass it in as optional into getUserMedia

var constraints = {   audio: {     optional: [{sourceId: audioSource}]   },   video: {     optional: [{sourceId: videoSource}]   } }; navigator.getUserMedia(constraints, successCallback, errorCallback); 

It is now fully available in Stable Chrome and mobile (As of v30)

like image 137
Kinlan Avatar answered Sep 19 '22 13:09

Kinlan


A demo can be found at https://webrtc.github.io/samples/src/content/devices/input-output/. This will allow access to both the front and rear camera.

Many demos that you will find rely on the deprecated function:

MediaStreamTrack.getSources()  

As of Chrome 45 and FireFox 39, you will need to use the function:

MediaDevices.enumerateDevices() 

Example:

if (!navigator.mediaDevices || !navigator.mediaDevices.enumerateDevices) {    console.log("enumerateDevices() not supported.");    return;  }    // List cameras and microphones.    navigator.mediaDevices.enumerateDevices()    .then(function(devices) {      devices.forEach(function(device) {        console.log(device.kind + ": " + device.label +          " id = " + device.deviceId);      });    })    .catch(function(e) {      console.log(e.name + ": " + e.message);    });

Further documentation can be found here: https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/enumerateDevices

like image 34
Jordan Steeves Avatar answered Sep 18 '22 13:09

Jordan Steeves