In my app I am using CameraX for screen recording. I am trying to save not just camera output, but also GUI layout presented over camera surface.
I am executing some basic animations on GUI layer( showing or hiding layouts and progress bar animations).
According to my knowledge, VideoCapture is capturing camera surface. So if I create custom surface for Camera, it should be possible to capture video with GUI layout.
How to set custom surface to CameraX? I was thinking about creating custom view(surface) from PreviewView but it is not possible. (PrevieView is final class) Is it possible to create custom surface provider? How?
PreviewView
<androidx.camera.view.PreviewView
android:id="@+id/view_finder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
...
Start of camera
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())
cameraProviderFuture.addListener(Runnable {
// Camera provider is now guaranteed to be available
val cameraProvider = cameraProviderFuture.get()
// Set up the preview use case to display camera preview.
val preview = Preview.Builder().apply {
setCameraSelector(CameraSelector.DEFAULT_FRONT_CAMERA)
}.build()
// Set up the capture use case to allow users to take photos.
videoCapture = VideoCapture.Builder().apply {
setCameraSelector(CameraSelector.DEFAULT_FRONT_CAMERA)
}.build()
// Choose the camera by requiring a lens facing
val cameraSelector = CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build()
// Attach use cases to the camera with the same lifecycle owner
val camera = cameraProvider.bindToLifecycle(
customLifecycle as LifecycleOwner, cameraSelector, preview, videoCapture)
// Connect the preview use case to the previewView
preview.setSurfaceProvider(
viewFinder.getSurfaceProvider())
}, ContextCompat.getMainExecutor(requireContext()))
}
