Last active
September 23, 2017 01:43
-
-
Save tcw165/fac091365c1c45311fd487db0635a725 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Activity or Fragment ::onResume | |
// 1. Wait for the surface ready. | |
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { | |
@Override | |
public void onSurfaceTextureAvailable(SurfaceTexture texture, | |
int width, int height) { | |
// 2. Open the camera. | |
manager.openCamera( | |
cameraId, | |
new CameraDevice.StateCallback() { | |
@Override | |
public void onOpened(CameraDevice device) { | |
// 3. Create a capture session. | |
device.createCaptureSession( | |
previewSurfaces, | |
new CameraCaptureSession.StateCallback() { | |
@Override | |
public void onConfigured(CameraCaptureSession session) { | |
// 4. Create a capture request. | |
mPreviewSession.setRepeatingRequest( | |
mPreviewBuilder.build(), | |
null, | |
mBackgroundHandler); | |
} | |
}, mBackgroundHandler); | |
} | |
}, | |
null); | |
} | |
}); | |
// Activity or Fragment ::onPause | |
if (captureSession != null) { | |
captureSession.close(); | |
captureSession = null; | |
} | |
if (cameraDevice != null) { | |
cameraDevice.close(); | |
cameraDevice = null; | |
} | |
if (previewReader != null) { | |
previewReader.close(); | |
previewReader = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment