Skip to content Skip to sidebar Skip to footer

Android Mediarecorder Stop Failed

I've faced a very strange behavior: sometimes my mediarecorder crashes with an error 'Stop failed' and sometimes it works fine. Is there my fault or it is a bug of the system? I ca

Solution 1:

You may catch a RuntimeException at the MediaRecorder.stop() method.

Example:

MediaRecordermRecorder=newMediaRecorder();
FilemFile=newFile("The output file's 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;
}

Solution 2:

If the recorder is not in a recording state, then the stop could fail.

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

Solution 3:

add following in your SurfaceCreated(SurfaceHolder holder):

CamcorderProfilecamcorderProfile= CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);  //get your own profile   
 Camera.Parametersparameters= mCamera.getParameters();  
 parameters.setPreviewSize(camcorderProfile.videoFrameWidth,camcorderProfile.videoFrameHeight);   
 mCamera.setParameters(parameters);  

Solution 4:

Experienced the same error: Sometimes my MediaRecorder crashed with an error "Stop failed" and sometimes it worked fine. Adding this solved my problem:

@OverridepublicvoidonStop() {
    super.onStop();
    if (mRecorder != null) {
        mRecorder.release();
        mRecorder = null;
    }
}

Post a Comment for "Android Mediarecorder Stop Failed"