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:

publicclassAndroidVideoCaptureextendsActivityimplementsSurfaceHolder.Callback{

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

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

    recording = false;

    mediaRecorder = newMediaRecorder();
    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);
}

privateButton.OnClickListener myButtonOnClickListener 
= newButton.OnClickListener(){

    @OverridepublicvoidonClick(View arg0) {
        // TODO Auto-generated method stubif(recording){
            mediaRecorder.stop();
            mediaRecorder.release();
            finish();
        }else{
            mediaRecorder.start();
            recording = true;
            myButton.setText("STOP");
        }
    }};

@OverridepublicvoidsurfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}
@OverridepublicvoidsurfaceCreated(SurfaceHolder arg0) {
    // TODO Auto-generated method stubprepareMediaRecorder();
}
@OverridepublicvoidsurfaceDestroyed(SurfaceHolder arg0) {
    // TODO Auto-generated method stub

}

privatevoidinitMediaRecorder(){

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

privatevoidprepareMediaRecorder(){
    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"