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