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

iMDroid picture iMDroid · Aug 2, 2017 · Viewed 15.3k times · Source

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.

Answer

Shailesh picture Shailesh · Aug 10, 2017

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..