add a helper function for setting camera parameters

This commit is contained in:
tibbi 2018-02-25 16:28:25 +01:00
parent 44fb913b0e
commit d02f391ed6
1 changed files with 18 additions and 9 deletions

View File

@ -169,7 +169,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE
mCamera!!.setDisplayOrientation(mActivity!!.getPreviewRotation(mCurrCameraId)) mCamera!!.setDisplayOrientation(mActivity!!.getPreviewRotation(mCurrCameraId))
mCamera!!.parameters = mParameters updateCameraParameters()
if (mCanTakePicture) { if (mCanTakePicture) {
try { try {
@ -265,7 +265,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
newZoomFactor = Math.min(mMaxZoom, newZoomFactor) newZoomFactor = Math.min(mMaxZoom, newZoomFactor)
mParameters!!.zoom = newZoomFactor mParameters!!.zoom = newZoomFactor
mCamera?.parameters = mParameters updateCameraParameters()
return true return true
} }
@ -297,7 +297,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mRotationAtCapture = mActivity!!.mLastHandledOrientation mRotationAtCapture = mActivity!!.mLastHandledOrientation
mCamera!!.parameters = mParameters updateCameraParameters()
isWaitingForTakePictureCallback = true isWaitingForTakePictureCallback = true
mIsPreviewShown = true mIsPreviewShown = true
try { try {
@ -396,7 +396,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_AUTO mParameters!!.focusMode = Camera.Parameters.FOCUS_MODE_AUTO
} }
mCamera!!.parameters = mParameters updateCameraParameters()
mCamera!!.autoFocus { success, camera -> mCamera!!.autoFocus { success, camera ->
if (camera == null || mCamera == null) { if (camera == null || mCamera == null) {
return@autoFocus return@autoFocus
@ -496,7 +496,7 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
mParameters = mCamera!!.parameters mParameters = mCamera!!.parameters
mParameters!!.setPreviewSize(mPreviewSize!!.width, mPreviewSize!!.height) mParameters!!.setPreviewSize(mPreviewSize!!.width, mPreviewSize!!.height)
mCamera!!.parameters = mParameters updateCameraParameters()
try { try {
mCamera!!.startPreview() mCamera!!.startPreview()
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
@ -579,22 +579,21 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
fun enableFlash() { fun enableFlash() {
mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_TORCH mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_TORCH
mCamera!!.parameters = mParameters updateCameraParameters()
} }
fun disableFlash() { fun disableFlash() {
mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF
mCamera!!.parameters = mParameters updateCameraParameters()
} }
fun autoFlash() { fun autoFlash() {
mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF mParameters!!.flashMode = Camera.Parameters.FLASH_MODE_OFF
mCamera!!.parameters = mParameters updateCameraParameters()
Handler().postDelayed({ Handler().postDelayed({
mActivity?.runOnUiThread { mActivity?.runOnUiThread {
mParameters?.flashMode = Camera.Parameters.FLASH_MODE_AUTO mParameters?.flashMode = Camera.Parameters.FLASH_MODE_AUTO
mCamera?.parameters = mParameters
} }
}, 1000) }, 1000)
} }
@ -653,6 +652,9 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
} }
checkPermissions() checkPermissions()
if (mRecorder == null) {
return false
}
mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface) mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface)
val rotation = getVideoRotation() val rotation = getVideoRotation()
@ -701,6 +703,13 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan
releaseCamera() releaseCamera()
} }
private fun updateCameraParameters() {
try {
mCamera?.parameters = mParameters
} catch (e: RuntimeException) {
}
}
fun toggleRecording(): Boolean { fun toggleRecording(): Boolean {
if (mIsRecording) { if (mIsRecording) {
stopRecording() stopRecording()