Example usage for android.graphics SurfaceTexture setOnFrameAvailableListener

List of usage examples for android.graphics SurfaceTexture setOnFrameAvailableListener

Introduction

In this page you can find the example usage for android.graphics SurfaceTexture setOnFrameAvailableListener.

Prototype

public void setOnFrameAvailableListener(@Nullable OnFrameAvailableListener listener) 

Source Link

Document

Register a callback to be invoked when a new image frame becomes available to the SurfaceTexture.

Usage

From source file:demo.camera.library.ui.CameraCaptureActivity.java

/**
 * Connects the SurfaceTexture to the Camera preview output, and starts the preview.
 *//*from   w w  w . j av  a  2s  . c o m*/
private void handleSetSurfaceTexture(SurfaceTexture st) {
    st.setOnFrameAvailableListener(this);
    try {
        mCameraManager.getCamera().setPreviewTexture(st);
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
    mCameraManager.getCamera().startPreview();
}

From source file:com.aimfire.demo.CamcorderActivity.java

/**
 * Connects the SurfaceTexture to the Camera preview output, and starts the preview.
 *///from  w w  w .  j  a v a 2 s . c  o  m
private void handleSetSurfaceTexture(SurfaceTexture st) {
    /*
     * when we restart camera after pausing, we tried to use preserved
     * EGL context by setPreserveEGLContextOnPause(true). however this
     * *may* fail on some devices that don't support multiple EGL
     * contexts (haven't come across any but according to documentation
     * this is possible). if that's the case, a new EGL context will be
     * created and we will get here. so to deal with it, we need first
     * stopPreview (as we tried startPreview on the old, potentially
     * invalid SurfaceTexture). when startPreview was not called (for
     * all the other reasons we get here), stopPreview has no negative
     * effect
     */
    mCamera.stopPreview();

    mCameraSurfaceTexture = st;
    st.setOnFrameAvailableListener(this);
    try {
        mCamera.setPreviewTexture(st);
        mCamera.startPreview();
    } catch (IOException e) {
        //throw new RuntimeException(e);
        if (BuildConfig.DEBUG)
            Log.e(TAG, "handleSetSurfaceTexture: cannot setPreviewTexture, surface destroyed");
        FirebaseCrash.report(e);
    }
}