
A bit of hack here. The old and deprecated way is to use the Camera object. But Google recommends using camera2 which is a more complex and new way of handling the camera(s) on the Android device.
It took a couple of days to hook the front camera, as it would just go to the back camera by default. Then it took another few days to handle the camera rotation part. The back camera requires more code to deal with because based on the position of the camera on the device (center, right, left) , you need code to figure out if the camera is in portrait mode or landscape mode and based on that how to rotate the camera capture in realtime.
The front camera is a little less tricky since its always in the center. The only thing to deal with is the orientation.
The implementation is a little messy because finally I had to use the older camera object along with the new camera 2 objects to make this thing work. Just for those who get stuck, the front camera needs to be unlocked before you can do anything with it.
The full project code is available on https://github.com/amitonline/android-video-camera

Leave a Reply