MediaRecorder second time recoriding prepare failed w/ Camera2
Opened this issue · 3 comments
I have been struggling for some time now on why I am not able to record for a second time with MediaRecorder. Every time I try it says:
Caused by: java.io.IOException: prepare failed.
I am not sure what I am doing wrong and frankly I have been staring at this for too long. I am doing this in Kotlin, but for the most part it is the same as Java with the exception of the function syntax. Please can anyone help? I have looked at others and the camera2 and mediarecorder being implemented, but it isn't working.
private val cameraCaptureCallback = object : CameraCaptureSession.CaptureCallback() {
private fun process(result: CaptureResult){
when(cameraState) {
STATE_PREVIEW -> {}
STATE_WAITING_LOCK -> {
val afState = result.get(CaptureResult.CONTROL_AF_STATE)
if(afState == null){
captureImage()
} else if(CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState
|| CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState){
val aeState = result.get(CaptureResult.CONTROL_AE_STATE)
if(aeState == null
|| aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED){
cameraState = STATE_PICTURE_TAKEN
captureImage()
} else {
runPrecaptureSequence()
}
}
}
STATE_WAITING_PRECAPTURE -> {
val aeState = result.get(CaptureResult.CONTROL_AE_STATE)
if(aeState == null
|| aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE
|| aeState == CaptureResult.CONTROL_AE_STATE_FLASH_REQUIRED) {
cameraState = STATE_WAITING_NON_PRECAPTURE
}
}
STATE_WAITING_NON_PRECAPTURE -> {
val aeState = result.get(CaptureResult.CONTROL_AE_STATE)
if(aeState == null
|| aeState != CaptureResult.CONTROL_AE_STATE_PRECAPTURE) {
cameraState = STATE_PICTURE_TAKEN
captureImage()
}
}
}
}
override fun onCaptureProgressed(session: CameraCaptureSession?, request: CaptureRequest?, partialResult: CaptureResult?) {
process(partialResult!!)
}
override fun onCaptureCompleted(session: CameraCaptureSession?, request: CaptureRequest?, result: TotalCaptureResult?) {
process(result!!)
}
}
private val cameraStateCallback = object : CameraDevice.StateCallback() {
override fun onOpened(camera: CameraDevice) {
cameraDevice = camera
createCameraPreview()
}
override fun onDisconnected(camera: CameraDevice) {
camera.close()
cameraDevice = null
}
override fun onError(camera: CameraDevice, error: Int) {
camera.close()
cameraDevice = null
if(activity != null)
activity.finish()
}
}
private val textureListener: TextureView.SurfaceTextureListener = object : TextureView.SurfaceTextureListener {
override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {
//open your camera here
setupCamera(width, height)
}
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {
}
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
return true
}
override fun onSurfaceTextureUpdated(surface: SurfaceTexture) {}
}
private val previewTextureListener: TextureView.SurfaceTextureListener = object : TextureView.SurfaceTextureListener {
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
try {
if(contentCaptured == "video"){
previewNewPostVideoMediaPlayer = MediaPlayer()
previewNewPostVideoMediaPlayer?.setDataSource(videoFile?.absolutePath)
previewNewPostVideoMediaPlayer?.setSurface(Surface(surface))
previewNewPostVideoMediaPlayer?.prepare()
previewNewPostVideoMediaPlayer?.start()
}
} catch (e: IllegalArgumentException ) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (e: SecurityException ) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (e: IllegalStateException ) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (e: IOException) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
override fun onSurfaceTextureSizeChanged(p0: SurfaceTexture?, p1: Int, p2: Int) {
}
override fun onSurfaceTextureUpdated(surfaceTexture: SurfaceTexture?) {
}
override fun onSurfaceTextureDestroyed(p0: SurfaceTexture?): Boolean {
return true
}
}
private fun createCameraPreview() {
if (cameraDevice == null || !cameraTextureView?.isAvailable!! || cameraPreviewDimension == null) {
return
}
try {
var texture: SurfaceTexture = cameraTextureView!!.surfaceTexture
texture.setDefaultBufferSize(cameraPreviewDimension!!.width, cameraPreviewDimension!!.height)
var surfaces: MutableList<Surface> = ArrayList()
captureRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW)
captureRequestBuilder?.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO)
var surface = Surface(texture)
captureRequestBuilder?.addTarget(surface)
surfaces.add(surface)
surfaces.add(cameraPreviewImageReader?.surface!!)
cameraDevice?.createCaptureSession(surfaces, object : CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession?) {
if (cameraDevice == null) {
return
}
try {
cameraCaptureSession = session
cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), null, mBackgroundHandler)
} catch (e: CameraAccessException){
e.printStackTrace()
}
}
override fun onConfigureFailed(cameraCaptureSession: CameraCaptureSession?) {
Log.e("Configuration session", "camera capture session failed in create preview")
}
}, mBackgroundHandler)
} catch(e: CameraAccessException) {
e.printStackTrace()
}
}
private fun createCameraOutput(width: Int, height: Int){
var cameraManager: CameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
try {
var cameraId = cameraManager.cameraIdList[0]
var cameraChars: CameraCharacteristics? = cameraManager.getCameraCharacteristics(cameraId)
var map: StreamConfigurationMap = cameraChars?.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP)!!
var max: Size = map.getOutputSizes(ImageFormat.JPEG)[0]
imageFile = createImageFile()
cameraPreviewImageReader = ImageReader.newInstance(max.width, max.height, ImageFormat.JPEG, 2)
cameraPreviewImageReader?.setOnImageAvailableListener(OnImageAvailableListener, mBackgroundHandler)
videoSize = map.getOutputSizes(SurfaceTexture::class.java)[0]
cameraPreviewDimension = map.getOutputSizes(SurfaceTexture::class.java)[0]
videoTextureView?.setAspectRatio(cameraPreviewDimension?.height!!, cameraPreviewDimension?.width!!)
cameraTextureView?.setAspectRatio(cameraPreviewDimension?.height!!, cameraPreviewDimension?.width!!)
configureTransform(width, height)
var available: Boolean = cameraChars.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)
mFlashSupported = available == null ?: available
cameraDeviceId = cameraId
} catch(e: CameraAccessException) {
e.printStackTrace()
}
}
private fun setupCamera(width: Int, height: Int) {
if(ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
var mainActivity = activity as MainActivity
ActivityCompat.requestPermissions(mainActivity!!, arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE), REQUEST_CAMERA_PERMISSION)
return
}
var cameraManager: CameraManager = activity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
createCameraOutput(width, height)
try {
cameraManager.openCamera(cameraDeviceId, cameraStateCallback, null)
cameraPreviewFrameLayout?.setOnTouchListener(OnCameraFeaturesListener)
} catch (e: CameraAccessException) {
e.printStackTrace()
} catch (e: InterruptedException) {
throw RuntimeException("Interrupted while trying to lock camera opening.", e);
}
}
private fun updateCameraPreview() {
if(cameraDevice == null) {
return
}
try {
cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
} catch(e: CameraAccessException) {
e.printStackTrace()
}
}
private fun takePicture(){
initFocus()
}
private fun initFocus(){
try {
captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START)
cameraState = STATE_WAITING_LOCK
cameraCaptureSession?.capture(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
} catch (e: CameraAccessException) {
e.printStackTrace()
}
}
private fun releaseFocus(){
try {
captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL)
cameraCaptureSession?.capture(captureRequestBuilder?.build(), null, mBackgroundHandler)
cameraState = STATE_PREVIEW
cameraCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), cameraCaptureCallback, mBackgroundHandler)
} catch (e: CameraAccessException ) {
e.printStackTrace()
}
}
private fun runPrecaptureSequence() {
try {
captureRequestBuilder?.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START)
cameraState = STATE_WAITING_PRECAPTURE;
cameraCaptureSession?.capture(captureRequestBuilder?.build(), cameraCaptureCallback,
mBackgroundHandler)
} catch (e: CameraAccessException ) {
e.printStackTrace()
}
}
private fun captureImage() {
if(cameraDevice == null){
return
}
try {
var tempCaptureBuilder: CaptureRequest.Builder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE)!!
tempCaptureBuilder.addTarget(cameraPreviewImageReader?.surface!!)
var camManager: CameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
var camChars: CameraCharacteristics = camManager.getCameraCharacteristics(cameraDevice?.id)
var rotation: Int = activity.windowManager.defaultDisplay.rotation
var actualRotation = getJpegOrientation(camChars, rotation)
tempCaptureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(actualRotation))
var tempCallback = object: CameraCaptureSession.CaptureCallback() {
override fun onCaptureCompleted(session: CameraCaptureSession?, request: CaptureRequest?, result: TotalCaptureResult?) {
releaseFocus()
}
}
cameraCaptureSession?.capture(tempCaptureBuilder.build(), tempCallback, null)
}
private fun setupRecorder() {
try {
videoFile = createVideoFile()
videoPath = videoFile?.path
} catch (e: IOException) {
e.printStackTrace()
}
if(mediaRecorder == null) {
mediaRecorder = MediaRecorder()
}
mediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)
mediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
mediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
mediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
mediaRecorder?.setOutputFile(videoPath)
mediaRecorder?.setVideoSize(videoSize?.width!!, videoSize?.height!!)
mediaRecorder?.setVideoFrameRate(30)
mediaRecorder?.setVideoEncodingBitRate(10000000)
mediaRecorder?.setOrientationHint(90)
}
private fun startRecordingVideo() {
if(cameraDevice == null || cameraPreviewDimension == null || !cameraTextureView?.isAvailable!!) {
return
}
try {
closeCameraSession()
setupRecorder()
mediaRecorder?.prepare()
var texture = cameraTextureView?.surfaceTexture
texture?.setDefaultBufferSize(cameraPreviewDimension?.width!!, cameraPreviewDimension?.height!!)
captureRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_RECORD)
captureRequestBuilder?.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO)
captureRequestBuilder?.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
var surfaces: MutableList<Surface> = ArrayList()
var previewSurface = Surface(texture)
var recorderSurface = mediaRecorder?.surface!!
Log.i("media recorder",mediaRecorder?.surface!!.toString())
var imageReaderSurface = cameraPreviewImageReader?.surface!!
surfaces.add(previewSurface)
surfaces.add(recorderSurface)
captureRequestBuilder?.addTarget(recorderSurface)
captureRequestBuilder?.addTarget(previewSurface)
cameraDevice?.createCaptureSession(surfaces, object : CameraCaptureSession.StateCallback() {
override fun onConfigured(session: CameraCaptureSession?) {
recordCaptureSession = session
try {
recordCaptureSession?.setRepeatingRequest(captureRequestBuilder?.build(), null, mBackgroundHandler)
} catch(e: CameraAccessException){
e.printStackTrace()
}
activity.runOnUiThread {
mediaRecorder?.start()
}
}
override fun onConfigureFailed(session: CameraCaptureSession?) {
Log.e("capture session error","session error")
}
}, mBackgroundHandler)
} catch(e: CameraAccessException){
e.printStackTrace()
}
}
private fun stopRecordingVideo() {
recordCaptureSession?.stopRepeating()
recordCaptureSession?.abortCaptures()
createCameraPreview()
if(mediaRecorder != null){
try {
} catch(e: CameraAccessException){
e.printStackTrace()
}
mediaRecorder?.stop()
mediaRecorder?.reset()
mediaRecorder?.setAudioSource(MediaRecorder.AudioSource.MIC)
mediaRecorder?.setVideoSource(MediaRecorder.VideoSource.SURFACE)
mediaRecorder?.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4)
mediaRecorder?.setVideoEncoder(MediaRecorder.VideoEncoder.H264)
mediaRecorder?.setAudioEncoder(MediaRecorder.AudioEncoder.AAC)
mediaRecorder?.setOutputFile(videoPath)
mediaRecorder?.setVideoSize(videoSize?.width!!, videoSize?.height!!)
mediaRecorder?.setVideoFrameRate(30)
mediaRecorder?.setVideoEncodingBitRate(10000000)
mediaRecorder?.setOrientationHint(90)
}
}
private fun startBackgroundThread() {
mBackgroundThread = HandlerThread("CameraBackground")
mBackgroundThread?.start()
mBackgroundHandler = Handler(mBackgroundThread?.looper)
}
private fun stopBackgroundThread() {
mBackgroundThread?.quitSafely()
try {
mBackgroundThread?.join()
mBackgroundThread = null
mBackgroundHandler = null
} catch(e: InterruptedException) {
e.printStackTrace()
}
}
private fun closeCamera() {
try {
if (cameraCaptureSession != null) {
cameraCaptureSession?.close()
cameraCaptureSession = null
}
if (cameraDevice != null) {
cameraDevice?.close()
cameraDevice = null
}
if(cameraPreviewImageReader != null){
cameraPreviewImageReader?.close()
cameraPreviewImageReader = null
}
if(mediaRecorder != null){
mediaRecorder?.reset()
mediaRecorder?.release()
mediaRecorder = null
}
} catch (e: InterruptedException) {
throw RuntimeException("Interrupted while trying to lock camera closing.", e)
}
}
}
Logcat:
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.162 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.182 31509-31509/ I/Flash info: true
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.192 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.192 31509-31509/ I/CameraManager: Using legacy camera HAL.
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:43.502 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:43.512 31509-31509/ I/camera: camera has been opened
11-28 01:13:43.562 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:43.572 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:43.572 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:43.572 31509-32334/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:43.612 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:43.612 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:43.612 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:43.612 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:44.353 31509-31520/ E/BufferQueueProducer: [unnamed-31509-2] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:44.353 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:44.463 31509-31520/ E/BufferQueueProducer: [unnamed-31509-2] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:45.794 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:46.315 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:46.365 31509-32334/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:46.605 31509-31509/ I/media recorder: Surface(name=null)/@0x1a8c1cd2
11-28 01:13:46.615 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:46.615 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:46.795 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:46.845 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:46.845 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:46.855 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:46.855 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:47.916 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:47.926 31509-31520/ E/BufferQueueProducer: [unnamed-31509-3] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:48.026 31509-31521/ E/BufferQueueProducer: [unnamed-31509-3] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:52.080 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:52.090 31509-32334/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:52.100 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:52.110 31509-32334/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:52.401 31509-32334/ D/Camera: app passed NULL surface
11-28 01:13:52.431 31509-32334/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:52.501 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:52.501 31509-32305/ I/RequestQueue: Repeating capture request set.
11-28 01:13:52.511 31509-32334/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:52.521 31509-32334/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:52.691 31509-31509/ I/here: video recording stop now
11-28 01:13:52.701 31509-31509/ I/Choreographer: Skipped 36 frames! The application may be doing too much work on its main thread.
11-28 01:13:52.781 31509-31509/ V/MediaPlayer-JNI: native_setup
11-28 01:13:52.781 31509-31509/ V/MediaPlayer: constructor
11-28 01:13:52.781 31509-31509/ V/MediaPlayer: setListener
11-28 01:13:52.781 31509-31509/ E/ExtMediaPlayer-JNI: QCMediaPlayer could not be located....
11-28 01:13:52.781 31509-31509/ E/MediaPlayer-JNI: QCMediaPlayer mediaplayer NOT present
11-28 01:13:52.791 31509-31509/ V/MediaPlayer-JNI: setDataSourceFD: fd 78
11-28 01:13:52.791 31509-31509/ V/MediaPlayer: setDataSource(78, 0, 576460752303423487)
11-28 01:13:52.801 31509-31521/ V/MediaPlayer: message received msg=8, ext1=0, ext2=0
11-28 01:13:52.801 31509-31521/ V/MediaPlayer: notify(8, 0, 0) callback on disconnected mediaplayer
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: setVideoSurfaceTexture
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: setVideoSurfaceTexture
11-28 01:13:52.851 31509-31509/ V/MediaPlayer: prepare
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: message received msg=5, ext1=1080, ext2=1440
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: New video size 1080 x 1440
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: callback application
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: back from callback
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: message received msg=1, ext1=0, ext2=0
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: prepared
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: signal application thread
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: callback application
11-28 01:13:53.031 31509-31509/ V/MediaPlayer: prepare complete - status=0
11-28 01:13:53.031 31509-31520/ V/MediaPlayer: back from callback
11-28 01:13:53.031 31509-31509/ E/MediaPlayer: Should have subtitle controller already set
11-28 01:13:53.031 31509-31509/ I/videoTV: android.graphics.SurfaceTexture@caa82cc
11-28 01:13:53.031 31509-31509/ I/videoTV: -1
11-28 01:13:53.031 31509-31509/ I/videoTV: -1
11-28 01:13:53.031 31509-31509/ V/MediaPlayer: getAudioStreamType
11-28 01:13:53.031 31509-31509/ V/MediaPlayer-JNI: getAudioStreamType: 3 (streamtype)
11-28 01:13:53.041 31509-31509/ V/MediaPlayer-JNI: start
11-28 01:13:53.041 31509-31509/ V/MediaPlayer: start
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: message received msg=300, ext1=0, ext2=0
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: Received SEC_MM_PLAYER_CONTEXT_AWARE
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.041 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.151 31509-31509/ W/MediaPlayer: this is IMEDIA_PLAYER_VIDEO_EXIST
11-28 01:13:53.151 31509-31509/ I/MediaPlayer: sendBroadcast android.media.IMediaPlayer.videoexist
11-28 01:13:53.151 31509-31509/ E/MediaPlayer: Should have subtitle controller already set
11-28 01:13:53.221 31509-32336/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:53.221 31509-31520/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: message received msg=6, ext1=0, ext2=0
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: Received MEDIA_STARTED
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.232 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.232 31509-31509/ V/MediaPlayer-JNI: getCurrentPosition: 0 (msec)
11-28 01:13:53.242 31509-31509/ V/MediaPlayer-JNI: isPlaying: 1
11-28 01:13:53.282 31509-31521/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: message received msg=200, ext1=3, ext2=0
11-28 01:13:53.382 31509-32391/ W/MediaPlayer: info/warning (3, 0)
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: callback application
11-28 01:13:53.382 31509-32391/ V/MediaPlayer: back from callback
11-28 01:13:53.882 31509-31509/ E/ContentValues: onPause
11-28 01:13:53.892 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:13:53.972 31509-31520/ W/MessageQueue: Handler (android.graphics.SurfaceTexture$1) {3592742a} sending message to a Handler on a dead thread
java.lang.IllegalStateException: Handler (android.graphics.SurfaceTexture$1) {3592742a} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:325)
at android.os.Handler.enqueueMessage(Handler.java:631)
at android.os.Handler.sendMessageAtTime(Handler.java:600)
at android.os.Handler.sendMessageDelayed(Handler.java:570)
at android.os.Handler.sendEmptyMessageDelayed(Handler.java:534)
at android.os.Handler.sendEmptyMessage(Handler.java:519)
at android.graphics.SurfaceTexture.postEventFromNative(SurfaceTexture.java:368)
11-28 01:13:53.982 31509-31521/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: BufferQueue has been abandoned
11-28 01:13:54.022 31509-32391/ E/BufferQueueProducer: [unnamed-31509-4] queueBuffer: BufferQueue has been abandoned
11-28 01:13:54.022 31509-31520/ E/BufferQueueProducer: [unnamed-31509-4] dequeueBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.172 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.182 31509-32334/ E/BufferQueueProducer: [unnamed-31509-4] cancelBuffer: BufferQueue has been abandoned
11-28 01:13:54.643 31509-31509/ E/ContentValues: onResume
11-28 01:13:54.643 31509-31509/ I/in here: wtf
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:54.643 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:54.653 31509-31509/ I/Flash info: true
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:54.653 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:54.663 31509-31509/ I/CameraManager: Using legacy camera HAL.
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value emboss
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value sketch
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value neon
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-warm
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value vintage-cold
11-28 01:13:55.033 31509-31509/ W/ArrayUtils: Ignoring invalid value washed
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value asd
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value back-light
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value flowers
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value AR
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value text
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value fall-color
11-28 01:13:55.043 31509-31509/ W/ArrayUtils: Ignoring invalid value dusk-dawn
11-28 01:13:55.053 31509-31509/ I/camera: camera has been opened
11-28 01:13:55.083 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state CONFIGURING
11-28 01:13:55.083 31509-32705/ I/RequestThread-0: Configure outputs: 2 surfaces configured.
11-28 01:13:55.083 31509-32705/ D/Camera: app passed NULL surface
11-28 01:13:55.093 31509-32705/ I/RequestThread-0: configureOutputs - set take picture size to 4128x3096
11-28 01:13:55.123 31509-31509/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:13:55.123 31509-31509/ I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e3b5f9 time:438855524
11-28 01:13:55.123 31509-32670/ I/RequestQueue: Repeating capture request set.
11-28 01:13:55.133 31509-32705/ W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
11-28 01:13:55.133 31509-32705/ W/LegacyRequestMapper: Only received metering rectangles with weight 0.
11-28 01:13:55.864 31509-32709/ I/CameraDeviceState: Legacy camera service transitioning to state CAPTURING
11-28 01:13:55.864 31509-32391/ E/BufferQueueProducer: [unnamed-31509-7] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=11 undequeued=0)
11-28 01:13:55.934 31509-32391/ E/BufferQueueProducer: [unnamed-31509-7] dequeueBuffer: min undequeued buffer count (2) exceeded (dequeued=10 undequeued=1)
11-28 01:13:55.984 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:57.626 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:13:58.747 31509-31521/ V/MediaPlayer: message received msg=2, ext1=0, ext2=0
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: playback complete
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: callback application
11-28 01:13:58.757 31509-31521/ V/MediaPlayer: back from callback
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: message received msg=7, ext1=0, ext2=0
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: unrecognized message: (7, 0, 0)
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: callback application
11-28 01:13:58.767 31509-31521/ V/MediaPlayer: back from callback
11-28 01:13:58.777 31509-31509/ V/MediaPlayer-JNI: getCurrentPosition: 5476 (msec)
11-28 01:13:58.777 31509-31509/ V/MediaPlayer-JNI: isPlaying: 0
11-28 01:13:58.857 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:02.921 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:04.533 31509-31509/ D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
11-28 01:14:05.033 31509-31509/ I/RequestQueue: Repeating capture request cancelled.
11-28 01:14:05.063 31509-32705/ I/CameraDeviceState: Legacy camera service transitioning to state IDLE
11-28 01:14:05.103 31509-31509/ E/MediaRecorder: prepare failed: -2147483648
11-28 01:14:05.103 31509-31509/ D/AndroidRuntime: Shutting down VM
11-28 01:14:05.113 31509-31509/ E/AndroidRuntime: FATAL EXCEPTION: main
Process: , PID: 31509
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.io.IOException: prepare failed.
at android.media.MediaRecorder._prepare(Native Method)
at android.media.MediaRecorder.prepare(MediaRecorder.java:873)
at .fragments.NewPostFragment.startRecordingVideo(NewPostFragment.kt:1455)
at .fragments.NewPostFragment.onLongClick(NewPostFragment.kt:589)
at android.view.View.performLongClick(View.java:5236)
at android.widget.TextView.performLongClick(TextView.java:10471)
at android.view.View$CheckForLongPress.run(View.java:20900)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
I'm having the same problem, did you get anywhere with this?
Same problem here. The setUpMediaRecorded() function fails when it reaches the default prepare method of the mediaRecorder and throws E/MediaRecorder: prepare failed: -2147483648 and because of that the startRecordingVideo() function which calls the above mentioned function throws E/FragmentPhoneCamera: java.io.IOException: prepare failed. I still can't figure out what is the reason for that crash and still struggling
having the same issue after 5-10+ times recording sessions one by one