public class record extends Activity implements OnClickListener, SurfaceHolder.Callback{
MediaRecorder recorder;
SurfaceHolder holder;
boolean recording=false;
public static final String TAG = "VIDEOCAPTURE";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.view);
SurfaceView cameraView = (SurfaceView) findViewById(R.id.surface_view);
holder = cameraView.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
cameraView.setClickable(true);
cameraView.setOnClickListener((OnClickListener) this);
}
private void initRecorder() {
File OutputFile = new File(Environment.getExternalStorageDirectory().getPath());
String video= "/DCIM/100MEDIA/Video";
CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(OutputFile.getAbsolutePath()+video+".3gp");
recorder.setMaxDuration(600000);
}
private void prepareRecorder() {
recorder.setPreviewDisplay(holder.getSurface());
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
finish();
} catch (IOException e) {
e.printStackTrace();
finish();
}
}
public void onClick(View v) {
if (recording) {
recorder.stop();
recording = false;
initRecorder();
prepareRecorder();
Toast display = Toast.makeText(this, "Stopped Recording", Toast.LENGTH_SHORT);
display.show();
} else {
recorder.start();
Log.v(TAG,"Recording Started");
recording = true;
}
}
public void surfaceCreated(SurfaceHolder holder) {
initRecorder();
Log.v(TAG,"surfaceCreated");
prepareRecorder();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
public void surfaceDestroyed(SurfaceHolder holder) {
if (recording) {
recorder.stop();
recording = false;
}
recorder.release();
finish();
}