CameraView icon indicating copy to clipboard operation
CameraView copied to clipboard

MediaRecorder: stop called in an invalid state: 0

Open ErickDaniel opened this issue 8 years ago • 9 comments

  • [x] I am using the latest version
  • [x] I can reproduce the bug in the demo app, and if not...
  • [x] I have tried to reproduce the bug in the demo app

Issue: no callback to error Class: Camera1

When code fails on Line: 586 Camera1.this.mMediaRecorder.start();

Call Line: 591 Camera1.this.endVideoImmediately();

But when code reach Line: 616 this.mMediaRecorder.stop();

Fail again and don't have callback and only log the error

In the commit the update is Line: 619 this.mCameraCallbacks.dispatchError(new CameraException(var2));

Error in log: 04-04 17:21:12.620 21520-21570/mx.demo.demoapp E/MediaRecorder: start failed: -38 04-04 17:21:12.622 21520-21570/mx.demo.demoapp E/Camera1: Error while starting MediaRecorder. Swallowing. java.lang.IllegalStateException java.lang.IllegalStateException at android.media.MediaRecorder._start(Native Method) at android.media.MediaRecorder.start(MediaRecorder.java:1170) at com.otaliastudios.cameraview.Camera1$14.run(Camera1.java:632) at com.otaliastudios.cameraview.Camera1$2.run(Camera1.java:62) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) 04-04 17:21:12.623 21520-21570/mx.demo.demoapp I/Camera1: endVideoImmediately: is capturing: true 04-04 17:21:12.624 21520-21570/mx.demo.demoapp I/MediaRecorderJNI: stop 04-04 17:21:12.624 21520-21570/mx.demo.demoapp E/MediaRecorder: stop called in an invalid state: 0 04-04 17:21:12.625 21520-21570/mx.demo.demoapp W/Camera1: endVideoImmediately: Error while closing media recorder. Swallowing java.lang.IllegalStateException java.lang.IllegalStateException at android.media.MediaRecorder._stop(Native Method) at android.media.MediaRecorder.stop(MediaRecorder.java:1199) at com.otaliastudios.cameraview.Camera1.endVideoImmediately(Camera1.java:662) at com.otaliastudios.cameraview.Camera1.access$1500(Camera1.java:26) at com.otaliastudios.cameraview.Camera1$14.run(Camera1.java:637) at com.otaliastudios.cameraview.Camera1$2.run(Camera1.java:62) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) 04-04 17:21:12.626 21520-21570/mx.demo.demoapp I/CameraCallbacks: dispatchError com.otaliastudios.cameraview.CameraException: java.lang.IllegalStateException com.otaliastudios.cameraview.CameraException: java.lang.IllegalStateException at com.otaliastudios.cameraview.Camera1.endVideoImmediately(Camera1.java:666) at com.otaliastudios.cameraview.Camera1.access$1500(Camera1.java:26) at com.otaliastudios.cameraview.Camera1$14.run(Camera1.java:637) at com.otaliastudios.cameraview.Camera1$2.run(Camera1.java:62) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61) Caused by: java.lang.IllegalStateException at android.media.MediaRecorder._stop(Native Method) at android.media.MediaRecorder.stop(MediaRecorder.java:1199) at com.otaliastudios.cameraview.Camera1.endVideoImmediately(Camera1.java:662) at com.otaliastudios.cameraview.Camera1.access$1500(Camera1.java:26)  at com.otaliastudios.cameraview.Camera1$14.run(Camera1.java:637)  at com.otaliastudios.cameraview.Camera1$2.run(Camera1.java:62)  at android.os.Handler.handleCallback(Handler.java:751)  at android.os.Handler.dispatchMessage(Handler.java:95)  at android.os.Looper.loop(Looper.java:154)  at android.os.HandlerThread.run(HandlerThread.java:61)  04-04 17:21:12.626 21520-21570/mx.demo.demoapp I/MediaRecorderJNI: release

ErickDaniel avatar Apr 04 '18 22:04 ErickDaniel

I Fork the project and add the next line mCameraCallbacks.dispatchError(new CameraException(e));

check it and let me know if I can do pull request

Regards

ErickDaniel avatar Apr 04 '18 22:04 ErickDaniel

Instead of passing this to the error callback, we would like to fix the error so it does not occur anymore. Thanks for the stack trace , if you have more info please add here

natario1 avatar Apr 07 '18 10:04 natario1

I think this could happen during configuration changes / activity destruction. In that case, it's intended behavior. We stop the recorder 'twice' in some conditions, and we ignore if it fails.

So please tell me, is this an app dysfunction (error, crash) or just a log that bothers you in logcat?

natario1 avatar Apr 07 '18 11:04 natario1

Well when I launch the camera, the screen shows the camera preview and need start the camera again to rec

ErickDaniel avatar Apr 09 '18 16:04 ErickDaniel

I think i'm experiencing the same problem. When I'm recording a video, I sometimes get a callback to OnVideoTaken without me calling stopCapturingVideo and the video I end up with is unplayable.

MaxMaes avatar Apr 11 '18 09:04 MaxMaes

@natario1 , same issue as @MaxMaes here. So we experience a crash, not only a log that bothers us.

willemjanvdun avatar Apr 11 '18 10:04 willemjanvdun

I seem to be able to reproduce the issue pretty consistently by doing the following:

  • When the app starts, start recording immediatly
  • Shake the phone while recording
  • After a second or two the recording fails

MaxMaes avatar Apr 11 '18 11:04 MaxMaes

I think the crash is fixed as this is an old issue. If not please open a new issue & link to a project that reproduces the issue.

About onVideoEnd being called please refer to #268 and see if you can help there.

natario1 avatar Dec 16 '18 16:12 natario1

Kindly check your camera or mic already in use by your app or other app.

tuabali avatar Aug 30 '22 04:08 tuabali