camera2 used. When I call closeCamera, last seen frame is displayed instead of black screen

137 views Asked by At

I implemented camera with 3 states: selfie(front), back and off.

It all works except the 'off' state.

I'm using camera2 and it is displayed on a TextureView:

<TextureView
    android:id="@+id/texture_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Expected: When 'off' state is chosen, I would like to close the camera and show black screen .

Actual: In 'off' state, the last seen frame of the camera is displayed.

closeCamera method:

private void closeCamera() {
    try {
        mCameraOpenCloseLock.acquire();
        closePreviewSession();
        if (null != mCameraDevice) {
            mCameraDevice.close();
            mCameraDevice = null;
        }
        if (null != mMediaRecorder) {
            mMediaRecorder.release();
            mMediaRecorder = null;
        }
    } catch (InterruptedException e) {
        throw new RuntimeException("Interrupted while trying to lock camera closing.");
    } finally {
        mCameraOpenCloseLock.release();
    }
}


private void closePreviewSession() {
    if (mPreviewSession != null) {
        mPreviewSession.close();
        mPreviewSession = null;
    }
}

Any idea how to cause 'closeCamera' to show black screen?

1

There are 1 answers

0
Eddy Talvala On BEST ANSWER

The simplest option is probably to overlay your TextureView with a separate black View when you close the camera.

Or hide the TextureView when not in use.