@Override
  public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
      if (!_isRecording) {
        _recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
        _recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        _recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);

        _recorder.setVideoEncodingBitRate(10000000);

        _recorder.setVideoFrameRate(5);

        _recorder.setVideoSize(100, 100);

        _recorder.setOutputFile("/sdcard/sample.3gp");
        _recorder.setPreviewDisplay(_holder.getSurface());

        try {
          _recorder.prepare();
        } catch (Exception e) {
          Log.e("test", "recorder error");
        }
        _recorder.start();
        _isRecording = true;

      } else {
        _recorder.stop();
        _recorder.reset();
        _isRecording = false;
      }
    }
    return true;
  }
 private void startRecording() {
   if (cameraBusy) return;
   System.out.println("start - lock enabled");
   cameraBusy = true;
   mCamera.unlock();
   recorder = new MediaRecorder();
   recorder.setCamera(mCamera);
   recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
   CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
   recorder.setOutputFormat(profile.fileFormat);
   recorder.setVideoFrameRate(profile.videoFrameRate);
   recorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
   recorder.setVideoEncodingBitRate(profile.videoBitRate);
   recorder.setVideoEncoder(profile.videoCodec);
   recorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
   recorder.setPreviewDisplay(mHolder.getSurface());
   try {
     recorder.prepare();
     recorder.start();
     recording = true;
     System.out.println("start - lock disabled");
   } catch (IllegalStateException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
   cameraBusy = false;
 }
예제 #3
0
파일: Record.java 프로젝트: bykrs/gifly
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private boolean prepareVideoRecorder() {

    // BEGIN_INCLUDE (configure_preview)
    mCamera = CameraHelper.getDefaultCameraInstance();

    Camera.Parameters parameters = mCamera.getParameters();
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    mCamera.setDisplayOrientation(90);
    mCamera.setParameters(parameters);

    // BEGIN_INCLUDE (configure_media_recorder)
    mMediaRecorder = new MediaRecorder();

    // Step 1: Unlock and set camera to MediaRecorder
    mCamera.unlock();

    // Camera.Parameters parameters = mCamera.getParameters();

    mMediaRecorder.setCamera(mCamera);
    CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_QVGA);

    // Log.d(TAG, profile.videoBitRate+"<- videoBitRate r");
    profile.videoBitRate = 1024000;

    // Step 2: Set sources
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    // Step 3: Set all values contained in profile except audio settings
    mMediaRecorder.setOutputFormat(profile.fileFormat);
    mMediaRecorder.setVideoEncoder(profile.videoCodec);
    mMediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
    mMediaRecorder.setVideoFrameRate(profile.videoFrameRate);
    mMediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
    mMediaRecorder.setOrientationHint(90);
    mMediaRecorder.setVideoFrameRate(24);

    // Step 4: Set output file
    save_to = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO).toString();
    mMediaRecorder.setOutputFile(save_to);

    mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

    // Step 5: Prepare configured MediaRecorder
    try {
      mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
      Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    } catch (IOException e) {
      Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
  @SuppressLint("NewApi")
  private boolean initRecorder() {
    if (!EaseCommonUtils.isExitsSdcard()) {
      showNoSDCardDialog();
      return false;
    }

    if (mCamera == null) {
      if (!initCamera()) {
        showFailDialog();
        return false;
      }
    }
    mVideoView.setVisibility(View.VISIBLE);
    // TODO init button
    mCamera.stopPreview();
    mediaRecorder = new MediaRecorder();
    mCamera.unlock();
    mediaRecorder.setCamera(mCamera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    // 设置录制视频源为Camera(相机)
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    if (frontCamera == 1) {
      mediaRecorder.setOrientationHint(270);
    } else {
      mediaRecorder.setOrientationHint(90);
    }
    // 设置录制完成后视频的封装格式THREE_GPP为3gp.MPEG_4为mp4
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    // 设置录制的视频编码h263 h264
    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    // 设置视频录制的分辨率。必须放在设置编码和格式的后面,否则报错
    mediaRecorder.setVideoSize(previewWidth, previewHeight);
    // 设置视频的比特率
    mediaRecorder.setVideoEncodingBitRate(384 * 1024);
    // // 设置录制的视频帧率。必须放在设置编码和格式的后面,否则报错
    if (defaultVideoFrameRate != -1) {
      mediaRecorder.setVideoFrameRate(defaultVideoFrameRate);
    }
    // 设置视频文件输出的路径
    localPath = PathUtil.getInstance().getVideoPath() + "/" + System.currentTimeMillis() + ".mp4";
    mediaRecorder.setOutputFile(localPath);
    mediaRecorder.setMaxDuration(30000);
    mediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
    try {
      mediaRecorder.prepare();
    } catch (IllegalStateException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }
예제 #5
0
  private void configureMediaRecorder() {
    mediaRecorder.setCamera(camera);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

    mediaRecorder.setVideoSize(1280, 720);
    mediaRecorder.setVideoEncodingBitRate(17000000);
    mediaRecorder.setVideoFrameRate(30);

    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
  }
 /**
  * Uses the settings from a CamcorderProfile object for recording. This method should be called
  * after the video AND audio sources are set, and before setOutputFile(). If a time lapse
  * CamcorderProfile is used, audio related source or recording parameters are ignored.
  *
  * @param profile the CamcorderProfile to use
  * @see android.media.CamcorderProfile
  */
 public void setProfile(CamcorderProfile profile) {
   setOutputFormat(profile.fileFormat);
   setVideoFrameRate(profile.videoFrameRate);
   setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
   setVideoEncodingBitRate(profile.videoBitRate);
   setVideoEncoder(profile.videoCodec);
   if (profile.quality >= CamcorderProfile.QUALITY_TIME_LAPSE_LOW
       && profile.quality <= CamcorderProfile.QUALITY_TIME_LAPSE_QVGA) {
     // Nothing needs to be done. Call to setCaptureRate() enables
     // time lapse video recording.
   } else {
     setAudioEncodingBitRate(profile.audioBitRate);
     setAudioChannels(profile.audioChannels);
     setAudioSamplingRate(profile.audioSampleRate);
     setAudioEncoder(profile.audioCodec);
   }
 }