mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-29 22:44:48 +01:00
properly close the camera on pause
This commit is contained in:
parent
c69e34a9b4
commit
a894f6e01c
@ -69,6 +69,7 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (hasStorageAndCameraPermissions()) {
|
||||
mPreview?.onResumed()
|
||||
resumeCameraItems()
|
||||
setupPreviewImage(mIsInPhotoMode)
|
||||
scheduleFadeOut()
|
||||
@ -84,7 +85,6 @@ class MainActivity : SimpleActivity(), PreviewListener, PhotoProcessor.MediaSave
|
||||
if (hasStorageAndCameraPermissions()) {
|
||||
mOrientationEventListener.enable()
|
||||
}
|
||||
mPreview?.onResumed()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -76,11 +76,8 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
}
|
||||
|
||||
override fun onPaused() {
|
||||
closeCamera()
|
||||
stopBackgroundThread()
|
||||
mCaptureSession?.close()
|
||||
mCameraDevice?.close()
|
||||
mCameraDevice = null
|
||||
mCaptureSession = null
|
||||
}
|
||||
|
||||
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture?, width: Int, height: Int) {
|
||||
@ -125,6 +122,21 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
}
|
||||
}
|
||||
|
||||
private fun closeCamera() {
|
||||
try {
|
||||
mCameraOpenCloseLock.acquire()
|
||||
mCaptureSession?.close()
|
||||
mCaptureSession = null
|
||||
mCameraDevice?.close()
|
||||
mCameraDevice = null
|
||||
mImageReader?.close()
|
||||
mImageReader = null
|
||||
} catch (e: Exception) {
|
||||
} finally {
|
||||
mCameraOpenCloseLock.release()
|
||||
}
|
||||
}
|
||||
|
||||
private val imageAvailableListener = ImageReader.OnImageAvailableListener { reader ->
|
||||
val image = reader.acquireNextImage()
|
||||
val buffer = image.planes[0].buffer
|
||||
@ -249,7 +261,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
mTextureView.setTransform(matrix)
|
||||
}
|
||||
|
||||
private var cameraStateCallback = object : CameraDevice.StateCallback() {
|
||||
private val cameraStateCallback = object : CameraDevice.StateCallback() {
|
||||
override fun onOpened(cameraDevice: CameraDevice) {
|
||||
mCameraOpenCloseLock.release()
|
||||
mCameraDevice = cameraDevice
|
||||
|
Loading…
x
Reference in New Issue
Block a user