views:

74

answers:

1

Hi, I am trying to record a video into sdCard. But everytime I click on the Button to record, it shows "stopped unexpectedly" error. Not too sure where went wrong. I am not sure if setOutputFile's path is how I should indicate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.camera);

    cam = new cameraview(this);
    ((FrameLayout) findViewById(R.id.preview)).addView(cam);
    // Create A Preview View

    buttonClick = (Button) findViewById(R.id.buttonClick);
    buttonClick.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if(toogleButtonFlag )
            {
                startRecording();
                toogleButtonFlag = false;
            }
            else{
                stopRecording();
                toogleButtonFlag = true;
            }

        }
    });
}

public void startRecording(){
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
     recorder.setOutputFile("/sdcard/.3pg");
     try{
     recorder.prepare();
     }
     catch(IOException e)
     {
         e.printStackTrace();
         recorder.reset();   
         recorder.release();
     }
     recorder.start();   // Recording is now started
}

public void stopRecording(){
     recorder.stop();
     recorder.reset();   
     recorder.release(); 
}
A: 
  1. Make sure you have the WRITE_EXTERNAL_STORAGE permission

  2. Your output file assumes the SD card is at /sdcard, which is incorrect on some devices and Android versions -- please use Environment.getExternalStorageDirectory()

  3. Your output file lacks a file name

  4. Your output file has a mis-spelled extension

CommonsWare