Search code examples
androidandroid-camerax

How do I lock/freeze a CameraX preview TextureView?


I'm following the CameraX code lab and also looked at their sample app and source code in Android Studio, but there doesn't seem to be a way to freeze or lock the TextureView that is showing the preview frames.

In the Camera2 API we can just call something like cameraCaptureSession?.stopRepeating() and the TextureView will stop getting input from the camera.

My use case for freezing the preview is to show the user the image that is currently being saved as I add other animations on top of the TextureView.


Solution

  • // You can unbind from any UseCase
    CameraX.unbind(previewUseCase)
    // In this way TextureView will hold the last frame
    
    
     // for version 1.0.0-alpha07
     cameraProvider.unbind(preview);