properly handle the case when surface is prepared earlier than the camera

This commit is contained in:
tibbi 2017-11-21 14:52:46 +01:00
parent 38785577b9
commit 1d2a5d225f
1 changed files with 6 additions and 0 deletions

View File

@ -50,6 +50,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
private var mIsSixteenToNine = false private var mIsSixteenToNine = false
private var mWasZooming = false private var mWasZooming = false
private var mIsPreviewShown = false private var mIsPreviewShown = false
private var mWasCameraPreviewSet = false
private var mLastClickX = 0 private var mLastClickX = 0
private var mLastClickY = 0 private var mLastClickY = 0
private var mCurrCameraId = 0 private var mCurrCameraId = 0
@ -132,6 +133,10 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
initRecorder() initRecorder()
} }
if (!mWasCameraPreviewSet && mIsSurfaceCreated) {
mCamera!!.setPreviewDisplay(mSurfaceHolder)
mWasCameraPreviewSet = true
}
return true return true
} }
@ -448,6 +453,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
override fun surfaceCreated(holder: SurfaceHolder) { override fun surfaceCreated(holder: SurfaceHolder) {
mIsSurfaceCreated = true mIsSurfaceCreated = true
try { try {
mWasCameraPreviewSet = mCamera != null
mCamera?.setPreviewDisplay(mSurfaceHolder) mCamera?.setPreviewDisplay(mSurfaceHolder)
if (mSwitchToVideoAsap) if (mSwitchToVideoAsap)