Hi!
I implemented a fragment, which recording video, pack data to MultipartBody and send it to server. This workes fine on Xiaomi Mi Play with Android 8, but on Xiaomi Redmi 8 with Android 9 i faced a crash, and i still cant find solution. The crash is produced when i am pushing a button to start recording. Here is stacktrace:
E/MediaRecorder: start failed: -19
E/MediaRecorder: stop called in an invalid state: 0
E/CameraEngine: onVideoResult result is null: something went wrong. java.lang.RuntimeException: start failed.
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at com.otaliastudios.cameraview.video.FullVideoRecorder.onStart(FullVideoRecorder.java:314)
at com.otaliastudios.cameraview.video.VideoRecorder.start(VideoRecorder.java:80)
at com.otaliastudios.cameraview.engine.Camera1Engine.onTakeVideo(Camera1Engine.java:425)
at com.otaliastudios.cameraview.engine.CameraBaseEngine$5.run(CameraBaseEngine.java:605)
at com.otaliastudios.cameraview.engine.orchestrator.CameraStateOrchestrator$3.run(CameraStateOrchestrator.java:100)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call(CameraOrchestrator.java:75)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call(CameraOrchestrator.java:72)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$2.onComplete(CameraOrchestrator.java:100)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$4.run(CameraOrchestrator.java:195)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.os.HandlerThread.run(HandlerThread.java:65)
And here is my CameraView settings in xml:
<com.otaliastudios.cameraview.CameraView
android:id="@+id/camera_view"
android:layout_width="@dimen/match_constraints"
android:layout_height="@dimen/match_constraints"
app:cameraAudioBitRate="4000000"
app:cameraAudioCodec="aac"
app:cameraFacing="back"
app:cameraMode="video"
app:cameraVideoBitRate="4000000"
app:cameraVideoCodec="h263"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
And my usage in fragment:
image_view_record_video.setOnClickListener {
image_view_record_video.animateInvisible(1000)
saveFile = File(requireContext().getExternalFilesDir(Environment.DIRECTORY_DCIM), "video.mp4")
startRecordingTimer()
camera_view.takeVideo(saveFile!!, 30000)
}
camera_view.addCameraListener(object : CameraListener() {
override fun onVideoTaken(result: VideoResult) {
super.onVideoTaken(result)
val requestFile = saveFile!!.asRequestBody(("multipart/form-data").toMediaType())
}
})
Also i am provided next permissions:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Will appreciate any help for solution of this problem. Thanks!
Also, i am using api ("com.otaliastudios:cameraview:2.6.4")
Is this crash is also occurring with camera 2 engine ?
I dont know, but ill try and inform you about results.
Still same result. I added app:cameraEngine="camera2" in my xml, and when i start video recording, i got this stacktrace again:
E/MediaRecorder: start failed: -19
E/MediaRecorder: stop called in an invalid state: 0
E/CameraEngine: onVideoResult result is null: something went wrong. java.lang.RuntimeException: start failed.
java.lang.RuntimeException: start failed.
at android.media.MediaRecorder.start(Native Method)
at com.otaliastudios.cameraview.video.FullVideoRecorder.onStart(FullVideoRecorder.java:314)
at com.otaliastudios.cameraview.video.VideoRecorder.start(VideoRecorder.java:80)
at com.otaliastudios.cameraview.engine.Camera1Engine.onTakeVideo(Camera1Engine.java:425)
at com.otaliastudios.cameraview.engine.CameraBaseEngine$5.run(CameraBaseEngine.java:605)
at com.otaliastudios.cameraview.engine.orchestrator.CameraStateOrchestrator$3.run(CameraStateOrchestrator.java:100)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call(CameraOrchestrator.java:75)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$1.call(CameraOrchestrator.java:72)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$2.onComplete(CameraOrchestrator.java:100)
at com.otaliastudios.cameraview.engine.orchestrator.CameraOrchestrator$4.run(CameraOrchestrator.java:195)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.os.HandlerThread.run(HandlerThread.java:65)
As result, video doesnt recorded.
@Radcat501 I am facing the same problem with Xiaomi Redmi note 7 running on Android 10 . Did you solve the problem ?
@achreffaidi still not, but i suggest, the problem is in new File creating in Android versions above 8. Looks like File does not properly created, so CameraView cant start recording.
@Radcat501 in my case, it works for the Selfie camera but Fails for the Main Camera. for some version under 2.6.4 it fails for both.
And yesterday it randomly worked with version 2.3.0 and when i rebuilt the project today the problem is back
@Radcat501 Updates ! I found the reason behind that exception. In my case it's because i am running ExoPlayer in another activity and i guess both of them are using Hardware acceleration for video. my temporary fix was adding
onPause(){
player.stop()
}
to the activity that using ExoPlayer.
and that works for me ... but it created another problem when i try to run the media player again.
@achreffaidi looks like in my case removing app:cameraVideoCodec="h263" removed the crash.
@achreffaidi looks like in my case removing app:cameraVideoCodec="h263" removed the crash.
@Radcat501 Following your steps, i fixed the problem by setting app:cameraVideoSizeBiggest="false" . I think recording the video using 48MP camera in Biggest video size is what required using the hardware acceleration . Though it's just a temporary fix.
This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.
Most helpful comment
@Radcat501 Updates ! I found the reason behind that exception. In my case it's because i am running ExoPlayer in another activity and i guess both of them are using Hardware acceleration for video. my temporary fix was adding
onPause(){ player.stop() }to the activity that using ExoPlayer.
and that works for me ... but it created another problem when i try to run the media player again.