Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access both back and front cameras simultaneously

Tags:

android

camera

What I'm trying to achieve: access both front and back cameras at the same time.

What I've researched: I know android camera API doesn't give support for using multiple instances of the Camera and you have to release a camera before using the other one. I've read tens of questions about this, I know on some devices it's possible (like Samsung S4, or other new devices from them). I've also found out that it's possible to have access to both of them in Android KitKat on SOME devices. I also know that on api >= 21, using the camera2 API, it's possible to access both of them at the same time because it's thread safe.

What I've got so far: implementation for accessing the cameras one at the time in order to provide a picture-in-picture.

I know it's not possible to implement dual simultaneously camera on every device, I just want a way to make it available to some devices.

How can I test to see if the device is capable of accessing both of them?

I've also searched for a library that can allow me such thing, but I didn't find anything. Is there such a library?

I would like to make this feature available for as many devices as possible, and for the others, I'll leave the current state (one by one) of the feature.

Can anyone please help me, at least with some pieces of advice?

Thanks !

like image 581
DDsix Avatar asked May 21 '15 14:05

DDsix


People also ask

Can I use the front and back camera at the same time?

The Dual Side camera is one of the best apps on PlayStore that can shoot videos from front and back cameras at the same time. Just follow these simple steps and you can also install and use this amazing app on your Android device: Download the DualSide camera from PlayStore or click here.

Can I use both cameras simultaneously?

Double Side Camera This app is one of the best apps for this and it uses the front & rear cameras of the phone simultaneously. You can take photos or record videos with both cameras. Other features include four types camera layouts, drag the camera layout to change it, etc. The app is very easy to use.


2 Answers

The Android camera APIs generally allow multiple cameras to be used at the same time, but most devices do not have enough hardware resources to support that in practice - for example, there's often only one camera image processor shared by both cameras.

There's no query that's included in the Android APIs that'll tell you up front if you can use multiple cameras at the same time.

The only way to tell is to try to open a second camera when you already have one open. If you can open the second camera, then you can do picture-in-picture, etc. If you get an exception trying to open the second camera, then that particular device doesn't support having both cameras open.

like image 150
Eddy Talvala Avatar answered Nov 15 '22 16:11

Eddy Talvala


It is possible using the Android Camera2 API, but as indicated above most devices don't have hardware support. If you have a Nexus 5X, Nexus 6, or Nexus 6P it will work and you can test with this BothCameras app. I've implemented blitting to allow video recording as well (in addition to still pictures) using the hardware h264 encoder.

like image 26
user2025983 Avatar answered Nov 15 '22 15:11

user2025983