prepare failed: -1 media recorder in android
<p>When i try to record video from camera which seems with an error prepare failed: -1.</p>

<p>I search lot and I cant get any acceptable answers from anywhere. here is my code below.</p>

<p>I don't know it by parameter? and by unlocking camera. Any one who can it will be grateful.</p>

<pre><code>package com.camara.activity;

import java.io.IOException;

import android.content.Context;
import android.hardware.Camera;
import android.media.MediaRecorder;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class CamcorderView extends SurfaceView implements
        SurfaceHolder.Callback {

    MediaRecorder recorder;
    SurfaceHolder holder;
    String outputFile = "/sdcard/default.mp4";

    public CamcorderView(Context context, AttributeSet attrs) {
        super(context, attrs);

        holder = getHolder();
        holder.addCallback(this);
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

        recorder = new MediaRecorder();
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
        recorder.setVideoSize(480, 320);
        recorder.setVideoFrameRate(10);
        recorder.setMaxDuration(10000);

    }

    public void surfaceCreated(SurfaceHolder holder) {

        recorder.setOutputFile(outputFile);
        recorder.setPreviewDisplay(holder.getSurface());
        if (recorder != null) {
            try {
                recorder.prepare();

            } catch (IllegalStateException e) {
                Log.e("IllegalStateException", e.toString());
            } catch (IOException e) {
                Log.e("IOException", e.toString());
            }
        }
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
    }

    public void surfaceDestroyed(SurfaceHolder holder) {
    }

    public void setOutputFile(String filename) {
        outputFile = filename;
        recorder.setOutputFile(filename);
    }

    public void startRecording() {
        recorder.start();
    }

    public void stopRecording() {
        recorder.stop();
        recorder.release();



    }

}
</code></pre>

<p>following is the output from the logcat</p>

<pre><code>01-10 17:33:00.450: I/MediaRecorderJNI(14046): prepare: surface=0x243398 (id=1)
01-10 17:33:00.500: E/MediaRecorder(14046): prepare failed: -1
01-10 17:33:00.500: E/IOException(14046): java.io.IOException: prepare failed.
</code></pre>

<p>thanks in advance.</p>
