Listen for TextureView first frame render

596 views Asked by At

I am implementing camera preview for scanning a QR code. Using TextureView to render the preview on. While camera and everything is initializing, there is a black screen, so I want to show a placeholder until camera starts rendering on the view. I used onSurfaceTextureAvailable to ask camera to start preview, but after asking camera to start preview the is a short delay where u see the black screen again, so I need a way to know when the preview actually started. Is this possible?

Thank you.

1

There are 1 answers

0
Perraco On BEST ANSWER

Try instead the onSurfaceTextureUpdated callback:

@Override
public void onSurfaceTextureUpdated(@NonNull final SurfaceTexture surface) {
    
    if (!this.isRendering) {
        this.isRendering = true;
        ... Remove the place holder
    }
}

Make sure to use a flag such as in the example, since if the implementation is for a camera app, then the callback will be triggered constantly on each camera frame, therefore use the flag to avoid calling your placeholder's removal code constantly none-stop.