Failed to stop recording in Android recorder.

I came across a very strange behavior: sometimes my media resource crashes with the "Stop failed" error, and sometimes it works fine. Is there my error or is it a system error? I canโ€™t understand whatโ€™s wrong.

private void stopRecording(){ ticker.cancel(); ticker.purge(); recorder.stop(); startBtn.setText("Start"); recordInProcess = false; markList = locWriteTask.getMarkArray(); mCamera.lock(); recorder.release(); } private void startRecording(){ startBtn.setText("Stop"); recordInProcess = true; recorder = new MediaRecorder(); mCamera.unlock(); recorder.setCamera(mCamera); recorder.setPreviewDisplay(mSurfaceHolder.getSurface()); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP); recorder.setMaxDuration((int) 10000000); recorder.setVideoSize(320, 240); recorder.setVideoFrameRate(15); recorder.setOutputFile(FULL_PATH_TO_LOCAL_FILE + counter + MP4); try{ recorder.prepare(); } catch (Exception e){ finish(); } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll); ticker = new Timer(); locWriteTask = new WriteTimeLocationTimerTask(ll); ticker.schedule(locWriteTask, 0, DELAY); recorder.start(); } 
+8
android video camera mediarecorder
source share
4 answers

If the recorder is not in the recording state, the stop may fail.

See http://developer.android.com/reference/android/media/MediaRecorder.html

+2
source share

You can detect a RuntimeException in the MediaRecorder.stop () method.

Example:

 MediaRecorder mRecorder = new MediaRecorder(); File mFile = new File("The output file absolutePath"); ... //config the mRecorder mRecorder.setOutputFile(mFile.getAbsolutePath()); ... //prepare() ... mRecorder.start(); try { mRecorder.stop(); } catch(RuntimeException e) { mFile.delete(); //you must delete the outputfile when the recorder stop failed. } finally { mRecorder.release(); mRecorder = null; } 
+8
source share

Add the following to your SurfaceCreated (SurfaceHolder holder):

 CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); //get your own profile Camera.Parameters parameters = mCamera.getParameters(); parameters.setPreviewSize(camcorderProfile.videoFrameWidth,camcorderProfile.videoFrameHeight); mCamera.setParameters(parameters); 
+2
source share

Experienced error: Sometimes my MediaRecorder crashed with the "Stop failed" error, and sometimes it worked fine. Adding this problem helped solve the problem:

 @Override public void onStop() { super.onStop(); if (mRecorder != null) { mRecorder.release(); mRecorder = null; } } 
0
source share

All Articles