Put a button in xml file, where you want open the camera for video recording.
here by i put the video recoding code.
this will create a folder in your sdcard/ or if no sdcard inserted it will use sytem inbult memory. hope u ll know..i dont need to explain a lot on this.
then map the below on click listener to the button you designed in your xml
Button recordButton =
(Button) findViewById(R.id.CaptureVid);
recordButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
String timestamp="1";
String timestamp = new SimpleDateFormat("MM-dd-yyyy_HH-mm-ss aa").format(Calendar.getInstance().getTime());
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath()+ "/samplevideofolder/");
dir.mkdirs();
File mediaFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/samplevideofolder/Video_"+timestamp+".avi");
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
Uri fileUri = Uri.fromFile(mediaFile);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
startActivityForResult(intent, VIDEO_CAPTURE);
}
});
put this code somewhere below , as function inside the main class
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VIDEO_CAPTURE) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Video saved to:\n" +data.getData(), Toast.LENGTH_LONG).show();
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Video recording cancelled.", Toast.LENGTH_LONG).show();
} else {
//Toast.makeText(this, "Failed to record video", Toast.LENGTH_LONG).show();
}
}
}
thats it, you are done with video recording..
in the above code you can find a line like this.
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 30);
this will automatically stops the video after 30 seconds,,,
if you want to record the video for more than that, unlimietd time.. just comment that line.. ok