From 966e2c5a36641baa3020db48ad72c63db78ce767 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 7 Apr 2019 23:16:40 +0200 Subject: [PATCH] catching some exceptions --- .../camera/views/CameraPreview.kt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/views/CameraPreview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/views/CameraPreview.kt index 36789450..f6efefdb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/views/CameraPreview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/views/CameraPreview.kt @@ -731,15 +731,15 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview { try { mPreviewRequestBuilder!!.apply { set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_IDLE) - mCaptureSession!!.capture(build(), mCaptureCallback, mBackgroundHandler) + mCaptureSession?.capture(build(), mCaptureCallback, mBackgroundHandler) } mCameraState = STATE_PREVIEW - mCaptureSession!!.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler) + mCaptureSession?.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler) if (mLastFocusX != 0f && mLastFocusY != 0f) { focusArea(mLastFocusX, mLastFocusY, false) } - } catch (e: CameraAccessException) { + } catch (e: Exception) { } finally { mCameraState = STATE_PREVIEW } @@ -816,9 +816,13 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview { surfaces.add(previewSurface) mPreviewRequestBuilder!!.addTarget(previewSurface) - val recorderSurface = mMediaRecorder!!.surface - surfaces.add(recorderSurface) - mPreviewRequestBuilder!!.addTarget(recorderSurface) + try { + val recorderSurface = mMediaRecorder!!.surface + surfaces.add(recorderSurface) + mPreviewRequestBuilder!!.addTarget(recorderSurface) + } catch (e: Exception) { + mActivity.showErrorToast(e) + } val captureCallback = object : CameraCaptureSession.StateCallback() { override fun onConfigured(session: CameraCaptureSession?) {