Skip to content Skip to sidebar Skip to footer

Android MediaRecorder Start Failed: -12

I've been trying to make an app (API 8) that records video, without audio. I've followed the instructions on the Android tutorial. My code is as follows: mCamera.unlock();

Solution 1:

So now I´ve tried an example and downloaded the sources. I modified it with Your code and it works without saving sound on API 8. Here is the main class:

    public class AndroidVideoCapture extends Activity implements SurfaceHolder.Callback{

Button myButton;
MediaRecorder mediaRecorder;
SurfaceHolder surfaceHolder;
boolean recording;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    recording = false;

    mediaRecorder = new MediaRecorder();
    initMediaRecorder();

    setContentView(R.layout.main);

    SurfaceView myVideoView = (SurfaceView)findViewById(R.id.videoview);
    surfaceHolder = myVideoView.getHolder();
    surfaceHolder.addCallback(this);
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    myButton = (Button)findViewById(R.id.mybutton);
    myButton.setOnClickListener(myButtonOnClickListener);
}

private Button.OnClickListener myButtonOnClickListener 
= new Button.OnClickListener(){

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        if(recording){
            mediaRecorder.stop();
            mediaRecorder.release();
            finish();
        }else{
            mediaRecorder.start();
            recording = true;
            myButton.setText("STOP");
        }
    }};

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stub
    prepareMediaRecorder();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

private void initMediaRecorder(){

    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
}

private void prepareMediaRecorder(){
    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    try {
        mediaRecorder.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

The difference to Your code is, that in this tutorial no camera is instantiated. It only works with MediaRecorder. The other difference is, that the prepare() and start() methods are separated. The MediaRecorder is initialized at starting the app, prepared when SurfaceView is created, and started at button click. Maybe You should try to seperate them too and don´t use camera. Please try it that way and give me a feedback if it works.


Solution 2:

Have You tried to set MediaRecorder Profile?

    recorder.setProfile(CamcorderProfile.get(camId, CamcorderProfile.QUALITY_LOW));

There is a similar question here in sof at:

MediaRecorder "start failed -12"


Post a Comment for "Android MediaRecorder Start Failed: -12"