Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Switch between front and back camera while recording a video

I am trying to implement Custom Camera to record a video. I have followed This sample and it is working fine.

Now, i want to add "Switch Camera" functionality over a Button click. It should be able to Switch between Front/Back Camera even while the video is getting recorded.

Hence please help me to know if it is even possible??

1. If yes then How??

2. If no then Please suggest some workaround??

Some sample codes or links would be very helpful...

Note : I have been googling about it and found some StackOverFlow answers like

Android Camera2 API switch back - front cameras

Android: Switch camera when button clicked

But none of these are giving a facility to switch the camera when the video is being recorded.

Please Help.

The code is same as This sample. And it's the Camera2 API.

like image 791
iMDroid Avatar asked Aug 02 '17 12:08

iMDroid


People also ask

Can Android record both cameras simultaneously?

Get Dual Camera app: Front and Back from Android PlayStore Once downloaded follow these steps: Tap on the camera icon at the centre. Choose the layout in which you want to shoot the video, and select video quality. The final step is just tapping on the record button.

How do I flip my camera on Android?

Tap the Tools option at the bottom of the screen, then select Rotate from the menu that appears. At the bottom of the display you'll see an icon the has two arrows pointing at each other, with a dotted vertical line between them. Tap this and you should see your image flip back to a normal orientation.


1 Answers

As far as i concerned, that camera is device and @Selvin explained front and back cameras are different devices.Now let me start from first,

Some of the device has own functionality that you can switch the camera during video is recording.like Nexus 9. For more detail please refer this question.

Another way you can do by using MediaRecorder. You can implement like this question's answer. how to switch between front and back camera when using MediaRecorder android?

I have no more idea about that but if you want to do then do like this:-

1. When your record video using back camera and switch to front camera then temporary save that video in local and star with front camera.
2. now stop the video recording then marge that both file and save as single file..

like image 171
Shailesh Avatar answered Sep 21 '22 17:09

Shailesh