1

I am developing an application in which i need to move from capture mode to recording mode(video) and vice versa.

Please help me for this I am cluless here, please suggest me if any tutorial available for this.

Any kind of help appreciated. Thank you.

2 Answers2

0

Use this method to open the camera in video mode

  private void dispatchTakeVideoIntent() {
        Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
        if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
            startActivityForResult(takeVideoIntent, 1);
        }
    }

please go through this url for further video basics

Use the following class

public class CaptureVideo extends Activity implements OnClickListener, SurfaceHolder.Callback{

    MediaRecorder recorder;
    SurfaceHolder holder;
    boolean recording=false;
    @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();// Instantiate our media recording object
        initialiseRecorder();
        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 initialiseRecorder() {
        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);// generally used also includes h264 and best for flash
        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;
            initialiseRecorder();
            prepareRecorder();
            Toast display = Toast.makeText(this, "Stopped Recording", Toast.LENGTH_SHORT);// toast shows a display of little sorts
            display.show();
        } else {
            recorder.start();
            recording = true;
        }
    }
    public void surfaceCreated(SurfaceHolder holder) {
        initialiseRecorder();
        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();
    }

}

Jiju Induchoodan
  • 4,236
  • 1
  • 22
  • 24
0

Create a Boolean variable Boolean video = false; Now depending on the switch state, toggle the value of the variable. Then whenever you want to start recording / take a picture just check the value of the video variable.

static final int REQUEST_IMAGE_CAPTURE = 1;
static final int REQUEST_VIDEO_CAPTURE = 2;

if(video) {

    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
    }
} else {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
    }

}
Shivam Verma
  • 7,973
  • 3
  • 26
  • 34
  • thank you for your answer. I want to make same as inbuilt feature of camara. camara is already start,dont want to achieve via intent. –  Jun 23 '14 at 09:46
  • http://stackoverflow.com/questions/14029057/how-to-open-camera-then-switch-to-image-mode-vice-versa – Shivam Verma Jun 23 '14 at 10:23