Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaRecorder.stop() hanging with Android 4.0 (ICS)

When calling stop() within my Video Capture activity, on occasion, the software will hang and will not come back to life. Only triggering an ANR by hitting "Back" will allow me to kill the activity.

Within the log, I see the following line repeated over and over:

W/CameraSource(YYYYY): Timed out waiting for incoming camera video frames: XXXXXX us

Has anyone else seen this behavior? Any workarounds?

like image 930
Adam Avatar asked Jan 18 '12 17:01

Adam


2 Answers

We've been struggling for this issue for a long time too. We have just copied the code from android developer site for capturing video but the application hangs before mediarecorder.stop() is called. Upon debugging almost line by line, I found out the ff. line causes the issue:

captureButton.setText("start");

I have commented it out and stopping the mediarecorder will no longer cause an ANR. What I did was instead of changing the text of the button, I just change the background.

captureButton.setBackgroundResource(R.drawable.icon_post_camera_record_main);

Without seeing your code, I'm not sure if we have the same cause of the issue but this fixes mine. I'm still searching why this happens for settext() and not for setBackgroundResource. My guess is that it has something to do with background/async task but it's still a guess.

like image 165
vida Avatar answered Oct 26 '22 04:10

vida


This also happened to me because I was releasing the camera before performing stop() on the recorder. It also explains the error message "Timed out waiting for incoming camera video frames". It's waiting for a camera that is already released. Make sure to stop the recorder - and only then release the camera:

mMediaRecorder.stop();
mMediaRecorder.release();

camera.stopPreview();
camera.release();
like image 44
gool Avatar answered Oct 26 '22 06:10

gool