Search code examples
androidandroid-camera2

How to properly pause/freeze CameraCaptureSession


I have question that relates to CameraCaptureSession lifecycle. I am building app that process camera2 preview started by CameraCaptureSession.setRepeatingRequest. I want to pauze/freeze that preview, that is being drawn into the canvas, wait for some kind of user action, and then eventually unpause it and continue.

I am unable to find any good info how to achieve this. I was thinking about .stopRepeating(), but then there will be no still image in preview. Could anyone share his thoughts on this or propose some kind of best practice? Maybe .stopRepeating() and some kind of dialog showing last still picture and then setRepeatingRequest again?


Solution

  • Generally, Android Views will keep the last buffer drawn to them until they receive new data.

    So if you're using a SurfaceView or a TextureView, calling stopRepeating should just freeze the preview at the last buffer sent from the camera.