Fix unbindFromSurface bug

pull/392/head
Mattia Iavarone 7 years ago
parent 1e7a4af4da
commit 4adf08107e
  1. 21
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java
  3. 4
      demo/src/main/AndroidManifest.xml

@ -66,7 +66,10 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
});
}
// Preview surface is now available. If camera is open, set up.
/**
* Preview surface is now available. If camera is open, set up.
* At this point we are sure that mPreview is not null.
*/
@Override
public void onSurfaceAvailable() {
LOG.i("onSurfaceAvailable:", "Size is", mPreview.getOutputSurfaceSize());
@ -80,8 +83,11 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
});
}
// Preview surface did change its size. Compute a new preview size.
// This requires stopping and restarting the preview.
/**
* Preview surface did change its size. Compute a new preview size.
* This requires stopping and restarting the preview.
* At this point we are sure that mPreview is not null.
*/
@Override
public void onSurfaceChanged() {
LOG.i("onSurfaceChanged, size is", mPreview.getOutputSurfaceSize());
@ -119,8 +125,11 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
return isCameraAvailable() && mPreview != null && mPreview.hasSurface() && !mIsBound;
}
// The act of binding an "open" camera to a "ready" preview.
// These can happen at different times but we want to end up here.
/**
* The act of binding an "open" camera to a "ready" preview.
* These can happen at different times but we want to end up here.
* At this point we are sure that mPreview is not null.
*/
@WorkerThread
private void bindToSurface() {
LOG.i("bindToSurface:", "Started");
@ -275,7 +284,7 @@ class Camera1 extends CameraController implements Camera.PreviewCallback, Camera
}
if (mCamera != null) {
stopPreview();
unbindFromSurface();
if (mIsBound) unbindFromSurface();
destroyCamera();
}
mCameraOptions = null;

@ -601,8 +601,7 @@ public class CameraView extends FrameLayout implements LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
public void open() {
if (!isEnabled()) return;
if (mCameraPreview == null) return; // Don't want to start without a preview
mCameraPreview.onResume();
if (mCameraPreview != null) mCameraPreview.onResume();
if (checkPermissions(getAudio())) {
// Update display orientation for current CameraController
mOrientationHelper.enable(getContext());

@ -15,9 +15,9 @@
<activity
android:name=".CameraActivity"
android:theme="@style/Theme.MainActivity"
android:hardwareAccelerated="true"
android:configChanges="orientation|screenLayout|keyboardHidden"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:hardwareAccelerated="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

Loading…
Cancel
Save