Code example for MediaRecorder: Recording audio and video

Methods: preparesetAudioEncodersetAudioSourcesetOutputFilesetOutputFormatsetPreviewDisplaysetVideoEncodersetVideoFrameRatesetVideoSizesetVideoSource

0
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
    } 
    else{ 
        recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
        recorder.setVideoFrameRate(30);
        recorder.setVideoSize(320, 240);
    } 
    recorder.setOutputFile(path);
    Surface s = holder.getSurface();
    recorder.setPreviewDisplay(s);
    recorder.prepare();
    recorder.start();
      } 
 
  /** 
   * Stops a recording that has been previously started. 
   */