How to access my android mobile's front and rear camera?

54 views
Skip to first unread message

Abhijit Sawant

unread,
Oct 25, 2016, 8:57:43 AM10/25/16
to discuss-webrtc
I am trying to switch between front and rear camera : 

Please have a look at this : jsfiddle.net/cf90az9q/19 

When I try this code using 2 webcams attached to my Desktop , I can easily switch between both the cameras. 
But when I browse to this code from chrome browser on my android phone. I can either access only the front or the rear camera but not both of them on every click. 
If I can access say.. front camera then next time when I click on the button I get a black screen and hence unable to open the rear camera..

Following line of code at line no.141 in javascript section toggles between 0 and 1 for every click and here '0' refers to front camera and '1' refers to rear camera.

 v = (v?0:1);
Please tell me how can I know which is front and rear camera and then how can I switch between them?


Christoffer Jansson

unread,
Oct 26, 2016, 3:08:11 AM10/26/16
to discuss-webrtc
Hi,

Android might not support having both cameras open at the same time, try to stop the video tracks of the already open camera before switching and see if that helps. Example of a simple code snippet to stop tracks can be found here.

/Chris

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/483b458f-6838-4e32-9e29-0c7d1512eee5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
/Chris

Kushtrim Pacaj

unread,
Oct 26, 2016, 1:24:17 PM10/26/16
to discuss-webrtc
There is a switchCamera method on CameraCaputurerAndroid class.
Reply all
Reply to author
Forward
0 new messages