How can I capture a video recording on Android?
How can I capture a video recording on Android?
Check out this Sample Camera Preview code, CameraPreview. This would help you in devloping video recording code for video preview, create MediaRecorder object, and set video recording parameters.
Currently (in the Year 2022) the Solution that should be most future-proof is the Android CameraX Library. https://developer.android.com/jetpack/androidx/releases/camera Sample Code can be found here: https://github.com/android/camera-samples
It is still in Alpha Status but for me the sample code works no problem on a Pixel 4a
Instead of writing code from the sketch, you can use a library on GitHub. For instance: https://github.com/CameraKit/camerakit-android (or https://github.com/google/cameraview, or https://github.com/hujiaweibujidao/CameraView and so on). Then you only need to:
private CameraKitView cameraKitView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraKitView = findViewById(R.id.camera);
}
@Override
protected void onStart() {
super.onStart();
cameraKitView.onStart();
}
@Override
protected void onResume() {
super.onResume();
cameraKitView.onResume();
}
@Override
protected void onPause() {
cameraKitView.onPause();
super.onPause();
}
@Override
protected void onStop() {
cameraKitView.onStop();
super.onStop();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
cameraKitView.onRequestPermissionsResult(requestCode, permissions, grantResults);
}