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,52 +821,23 @@ class CameraPreview : ViewGroup, TextureView.SurfaceTextureListener, MyPreview {
|
|||||||
mMediaActionSound.play(MediaActionSound.START_VIDEO_RECORDING)
|
mMediaActionSound.play(MediaActionSound.START_VIDEO_RECORDING)
|
||||||
}
|
}
|
||||||
|
|
||||||
val texture = mTextureView.surfaceTexture
|
|
||||||
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
|
||||||
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_RECORD).apply {
|
|
||||||
set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD)
|
|
||||||
set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getFrameRange())
|
|
||||||
}
|
|
||||||
|
|
||||||
val surfaces = ArrayList<Surface>()
|
|
||||||
val previewSurface = Surface(texture)
|
|
||||||
surfaces.add(previewSurface)
|
|
||||||
mPreviewRequestBuilder!!.addTarget(previewSurface)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
val texture = mTextureView.surfaceTexture
|
||||||
|
texture.setDefaultBufferSize(mPreviewSize!!.width, mPreviewSize!!.height)
|
||||||
|
mPreviewRequestBuilder = mCameraDevice!!.createCaptureRequest(CameraDevice.TEMPLATE_RECORD).apply {
|
||||||
|
set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_VIDEO_RECORD)
|
||||||
|
set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getFrameRange())
|
||||||
|
}
|
||||||
|
|
||||||
|
val surfaces = ArrayList<Surface>()
|
||||||
|
val previewSurface = Surface(texture)
|
||||||
|
surfaces.add(previewSurface)
|
||||||
|
mPreviewRequestBuilder!!.addTarget(previewSurface)
|
||||||
|
|
||||||
val recorderSurface = mMediaRecorder!!.surface
|
val recorderSurface = mMediaRecorder!!.surface
|
||||||
surfaces.add(recorderSurface)
|
surfaces.add(recorderSurface)
|
||||||
mPreviewRequestBuilder!!.addTarget(recorderSurface)
|
mPreviewRequestBuilder!!.addTarget(recorderSurface)
|
||||||
} catch (e: Exception) {
|
mCameraDevice!!.createCaptureSession(surfaces, getCameraCaptureCallback(), mBackgroundHandler)
|
||||||
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)
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
mActivity.showErrorToast(e)
|
mActivity.showErrorToast(e)
|
||||||
mCameraState = STATE_PREVIEW
|
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 {
|
private fun getAvailableVideoSizes(configMap: StreamConfigurationMap) = configMap.getOutputSizes(MediaRecorder::class.java).filter {
|
||||||
it.width <= MAX_VIDEO_WIDTH && it.height <= MAX_VIDEO_HEIGHT
|
it.width <= MAX_VIDEO_WIDTH && it.height <= MAX_VIDEO_HEIGHT
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user