Huzaifa Asif
Huzaifa Asif

Reputation: 664

How to use front and back camera at the same time?

I want to use both front and back cameras at the same time. I have used two surface views. I have tried to implement the code in following answer.

https://stackoverflow.com/a/24238301/6874315

The problem is that the camera API is now deprecated and the code was too old. I tried using the Camera 2 API in the same way but the camera instance won't open and i get a blank white screen. I get the following two errors:

Camera 0 not available! java.lang.RuntimeException: Fail to connect to camera service

Camera 1 not available! java.lang.RuntimeException: Fail to connect to camera service

What i wanna do is capture picture from front and back camera simultaneously on a button click. But i'm not able to open both front and back cameras at the same time. Is there anything that I do to use both cameras at same time?

Upvotes: 2

Views: 1134

Answers (2)

Hadi Haidar
Hadi Haidar

Reputation: 337

Take a look at these answers:

https://stackoverflow.com/a/30444841/11338123

https://stackoverflow.com/a/52075569/11338123

I think it is possible in some devices and it is impossible in others

Upvotes: 1

Egor Richman
Egor Richman

Reputation: 679

I don't sure that it is possible to use both cameras simultaneously. But, you could switching between two cameras like in this sample for short time interval.

Also you can modify you program to process camera images in the background thread in such way to avoid GUI freezing.

So, you may try to make a little changes in the sample to get front and back camera instances for testing your idea. Good luck!

Upvotes: 0

Related Questions