Android video app get camera device id
The android video app get camera device id tutorial describes how to select the camera on the device that you would want to use for your android video application.
Normal in smartphone devices you would expect to see two camera’s one front facing normally used for selfie mode and a main rear facing camera.
In this tutorial we will be hard coding in the rear camera to be used for the video capture part of the android video application.
This tutorial will show one way to select the rear camera by its camera id value and also how to get a map of the stream configurations which will provide the details of the camera resolutions for video and preview for this particular case.
Get Code
The code to start this tutorial is on github here
https://github.com/mobapptuts/android_camera2_api_video_app.git Tag camera2-video-camera-id
or you can run this command
git clone https://github.com/mobapptuts/android_camera2_api_video_app.git –branch camera2-video-camera-id
Steps
Create a member for the camera device id
private String mCameraId;
Find the camera device id, get the stream configuration map and set the member cameraId
private void setupCamera(int viewWidth, int viewHeight) { CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); try { for(String cameraId : cameraManager.getCameraIdList()) { CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId); if(cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT){ continue; } mCameraId = cameraId; return; } } catch (CameraAccessException e) { e.printStackTrace(); } }
Android video app get camera device id summary
In the android video app get camera device summary tutorial we were learnt how to
- Get the CameraManager from android
- Find the camera device id from the CameraManager getDeviceIdList method
- Ignore the front facing camera
- Get the CameraCharacteristics from the CameraManager
- Get the StreamConfiguration map from the CameraCharacteristics.