From ae77fb31ddea9098f8f4d565b3a418207169d209 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Sun, 11 Jun 2017 08:10:53 -0400 Subject: [PATCH] Add check for isStarted to avoid multiple start/stop calls. --- .../java/com/flurgle/camerakit/CameraView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java index d60ea73f..cc3b530e 100644 --- a/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java +++ b/camerakit/src/main/java/com/flurgle/camerakit/CameraView.java @@ -81,6 +81,8 @@ public class CameraView extends FrameLayout { private PreviewImpl mPreviewImpl; + private boolean mIsStarted; + public CameraView(@NonNull Context context) { super(context, null); init(context, null); @@ -121,6 +123,7 @@ public class CameraView extends FrameLayout { mPreviewImpl = new TextureViewPreview(context, this); mCameraImpl = new Camera1(mCameraListener, mPreviewImpl); + mIsStarted = false; setFacing(mFacing); setFlash(mFlash); setFocus(mFocus); @@ -202,7 +205,16 @@ public class CameraView extends FrameLayout { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } + public boolean isStarted() { + return mIsStarted; + } + public void start() { + if (mIsStarted) { + // Already started, do nothing. + return; + } + mIsStarted = true; int cameraCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA); int audioCheck = ContextCompat.checkSelfPermission(getContext(), Manifest.permission.RECORD_AUDIO); @@ -238,6 +250,11 @@ public class CameraView extends FrameLayout { } public void stop() { + if (!mIsStarted) { + // Already stopped, do nothing. + return; + } + mIsStarted = false; mCameraImpl.stop(); }