开发者

Android Records a Video into SDCard

I am trying to record a video into sdCard. But everytime I click on the Button to record, it shows "stopped unexpectedly" error.开发者_JAVA百科 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(); 
}


  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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜