mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-18 04:10:45 +01:00
catch more exceptions at toggling to recording mode
This commit is contained in:
parent
a713f8aba6
commit
f7e0b711cb
@ -821,6 +821,7 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
||||
mMediaActionSound.play(MediaActionSound.START_VIDEO_RECORDING)
|
||||
}
|
||||
|
||||
try {
|
||||
val texture = mTextureView.surfaceTexture
|
||||
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
||||
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_RECORD).apply {
|
||||
@ -833,40 +834,10 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
||||
surfaces.add(previewSurface)
|
||||
mPreviewRequestBuilder!!.addTarget(previewSurface)
|
||||
|
||||
try {
|
||||
val recorderSurface = mMediaRecorder!!.surface
|
||||
surfaces.add(recorderSurface)
|
||||
mPreviewRequestBuilder!!.addTarget(recorderSurface)
|
||||
} catch (e: Exception) {
|
||||
mActivity.showErrorToast(e)
|
||||
mCameraState = STATE_PREVIEW
|
||||
return
|
||||
}
|
||||
|
||||
val captureCallback = object : CameraCaptureSession.StateCallback() {
|
||||
override fun onConfigured(session: CameraCaptureSession) {
|
||||
mCaptureSession = session
|
||||
updatePreview()
|
||||
mIsRecording = true
|
||||
mActivity.runOnUiThread {
|
||||
try {
|
||||
mMediaRecorder?.start()
|
||||
} catch (e: Exception) {
|
||||
mActivity.showErrorToast(e)
|
||||
mCameraState = STATE_PREVIEW
|
||||
}
|
||||
}
|
||||
mActivity.setRecordingState(true)
|
||||
mCameraState = STATE_RECORDING
|
||||
}
|
||||
|
||||
override fun onConfigureFailed(session: CameraCaptureSession) {
|
||||
mCameraState = STATE_PREVIEW
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
mCameraDevice!!.createCaptureSession(surfaces, captureCallback, mBackgroundHandler)
|
||||
mCameraDevice!!.createCaptureSession(surfaces, getCameraCaptureCallback(), mBackgroundHandler)
|
||||
} catch (e: Exception) {
|
||||
mActivity.showErrorToast(e)
|
||||
mCameraState = STATE_PREVIEW
|
||||
@ -900,6 +871,32 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCameraCaptureCallback(): CameraCaptureSession.StateCallback {
|
||||
val callback = object : CameraCaptureSession.StateCallback() {
|
||||
override fun onConfigured(session: CameraCaptureSession) {
|
||||
mCaptureSession = session
|
||||
updatePreview()
|
||||
mIsRecording = true
|
||||
mActivity.runOnUiThread {
|
||||
try {
|
||||
mMediaRecorder?.start()
|
||||
} catch (e: Exception) {
|
||||
mActivity.showErrorToast(e)
|
||||
mCameraState = STATE_PREVIEW
|
||||
}
|
||||
}
|
||||
mActivity.setRecordingState(true)
|
||||
mCameraState = STATE_RECORDING
|
||||
}
|
||||
|
||||
override fun onConfigureFailed(session: CameraCaptureSession) {
|
||||
mCameraState = STATE_PREVIEW
|
||||
}
|
||||
}
|
||||
|
||||
return callback
|
||||
}
|
||||
|
||||
private fun getAvailableVideoSizes(configMap: StreamConfigurationMap) = configMap.getOutputSizes(MediaRecorder::class.java).filter {
|
||||
it.width <= MAX_VIDEO_WIDTH && it.height <= MAX_VIDEO_HEIGHT
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user