Android mediarecorder stop failed

前端 未结 4 1814
旧巷少年郎
旧巷少年郎 2021-01-17 12:24

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 sy

相关标签:
4条回答
  • 2021-01-17 13:02

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

    @Override
    public void onStop() {
        super.onStop();
        if (mRecorder != null) {
            mRecorder.release();
            mRecorder = null;
        }
    }
    
    0 讨论(0)
  • 2021-01-17 13:09

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

    Example:

    MediaRecorder mRecorder = new MediaRecorder();
    File mFile = new File("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;
    }
    
    0 讨论(0)
  • 2021-01-17 13:16

    add following in 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);  
    
    0 讨论(0)
  • 2021-01-17 13:22

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

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

    0 讨论(0)
提交回复
热议问题