示例#1
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;
  }
  private boolean prepareMediaRecorder() {
    myCamera = getCameraInstance(switchCam);
    Camera.Parameters parameters = myCamera.getParameters();
    parameters.setFlashMode(getFlashModeSetting());
    if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
      myCamera.setDisplayOrientation(90);
    } else {
      myCamera.setDisplayOrientation(0);
    }

    myCamera.setParameters(parameters);
    myCamera.unlock();

    mediaRecorder = new MediaRecorder();
    mediaRecorder.setCamera(myCamera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    if (switchCam == 1) {
      mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
      mediaRecorder.setVideoFrameRate(15);
    } else {
      mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
      mediaRecorder.setVideoFrameRate(30);
    }

    if (switchCam == 0) {
      if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {
        mediaRecorder.setOrientationHint(90);
      } else {
        mediaRecorder.setOrientationHint(0);
      }
    } else {
      mediaRecorder.setOrientationHint(270);
    }

    mediaRecorder.setOutputFile("/sdcard/" + customVideoPath + ".mp4");
    mediaRecorder.setMaxDuration(240000); // Set max duration 4 mins.
    mediaRecorder.setMaxFileSize(8000000); // Set max file size 8M
    mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());

    try {
      mediaRecorder.prepare();
    } catch (IllegalStateException e) {
      releaseMediaRecorder();
      return false;
    } catch (IOException e) {
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
示例#3
0
 private void setUpSupportedProfiles() {
   this.qualities = new Array<String>(false, 3);
   if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
     if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) {
       this.qualities.add(DeviceVideoControl.P1080);
     }
     if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
       this.qualities.add(DeviceVideoControl.P720);
     }
     if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) {
       this.qualities.add(DeviceVideoControl.P480);
     }
   }
   this.currentProfile = this.qualities.size == 0 ? "" : this.qualities.first();
 }
示例#4
0
  public void startRecording(View view) {
    try {
      if (!Utils.isIntentAvailable(this, MediaStore.ACTION_VIDEO_CAPTURE)) {
        Toast.makeText(this, "No camera available", Toast.LENGTH_SHORT).show();
        return;
      }

      camera.unlock();
      recorder = new MediaRecorder();
      recorder.setCamera(camera);

      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

      recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
      // no need to set setOutputFormat, setAudioEncoder, setVideoEncoder
      // when I set the profile instead?

      recorder.setOutputFile(Utils.getOutputMediaFilePath(Utils.MEDIA_TYPE_VIDEO));

      recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface());

      recorder.prepare();
      recorder.start();

      Log.i(TAG, "Recording started");

    } catch (Exception e) {
      releaseMediaRecorder();
      Log.e(TAG, e.getMessage());
      e.printStackTrace();
    }
  }
 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;
 }
 private boolean prepareVideoRecorder() {
   if (mCamera == null) {
     mCamera = getCameraInstance();
   }
   mMediaRecorder = new MediaRecorder();
   // Step 1: Unlock and set camera to MediaRecorder
   mCamera.unlock();
   mMediaRecorder.setCamera(mCamera);
   // Step 2: Set sources
   mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
   mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
   // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
   mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
   // Step 4: Set output file
   mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
   // Step 5: Set the preview output
   mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
   // Step 6: 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;
 }
示例#7
0
 public void activate() {
   if (camera.open()) {
     camera.startPreview();
     if (camera.unlock()) {
       try {
         this.setCamera(camera.getCamera());
         this.setAudioSource(MediaRecorder.AudioSource.MIC);
         this.setVideoSource(MediaRecorder.VideoSource.CAMERA);
         this.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
         this.setOutputFile(FileManager.getOutputMediaFile(MEDIA_TYPE_VIEDO).getAbsolutePath());
         this.prepare();
         this.start();
         isRunning = true;
       } catch (final Exception e) {
         Runnable runnable =
             new Runnable() {
               @Override
               public void run() {
                 Toast toast1 =
                     (Toast.makeText(
                         callingActivity,
                         "Problem with Recorder!" + e.getMessage(),
                         Toast.LENGTH_LONG));
                 toast1.show();
                 e.printStackTrace();
                 deactivate();
               }
             };
         callingActivity.runOnUiThread(runnable);
         isRunning = false;
       }
     }
   }
 }
  // gets called by the button press
  public void startRecording(View v) {
    recordingTime = 0;
    progressBar.setProgress(recordingTime);

    Log.d(TAG, "startRecording()");
    // we need to unlock the camera so that mediaRecorder can use it
    this.camera.unlock(); // unnecessary in API >= 14
    // now we can initialize the media recorder and set it up with our
    // camera
    this.mediaRecorder = new MediaRecorder();
    this.mediaRecorder.setCamera(this.camera);
    this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    // mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    // mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
    // mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    this.mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
    this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath());
    this.mediaRecorder.setPreviewDisplay(this.cameraPreview.getHolder().getSurface());
    try {
      this.mediaRecorder.prepare();
      // start the actual recording
      // throws IllegalStateException if not prepared
      this.mediaRecorder.start();
      // Toast.makeText(this, R.string.recording, Toast.LENGTH_SHORT).show();
      // enable the stop button by indicating that we are recording
    } catch (Exception e) {
      Log.wtf(TAG, "Failed to prepare MediaRecorder", e);
      // Toast.makeText(this, R.string.cannot_record, Toast.LENGTH_SHORT).show();
      this.releaseMediaRecorder();
    }
  }
 @Override
 public void run() {
   camera.stopPreview();
   camera.unlock();
   recorder = new MediaRecorder();
   recorder.setCamera(camera);
   recorder.setPreviewDisplay(surfaceHolder.getSurface());
   recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
   recorder.setPreviewDisplay(surfaceHolder.getSurface());
   recorder.setAudioChannels(vaudio_ch);
   recorder.setAudioSamplingRate(vaudio_samplerate);
   recorder.setAudioEncodingBitRate(vaudio_bitrate);
   recorder.setVideoEncodingBitRate(video_bitrate);
   recorder.setVideoSize(video_width, video_height);
   recorder.setVideoFrameRate(video_fps);
   long time = System.currentTimeMillis();
   Date date = new Date(time);
   SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");
   recorder.setOutputFile("/sdcard/ez_Lua_Script_Camera/VIDEO/" + sdf.format(date) + ".mp4");
   try {
     recorder.prepare();
   } catch (IOException e) {
   }
   recorder.start();
 }
示例#10
0
 private CamcorderProfile getProfile() {
   CamcorderProfile prof = null;
   if (this.currentProfile.equals(DeviceVideoControl.P480)) {
     prof = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
   } else if (this.currentProfile.equals(DeviceVideoControl.P720)) {
     prof = CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
   } else if (this.currentProfile.equals(DeviceVideoControl.P1080)) {
     prof = CamcorderProfile.get(CamcorderProfile.QUALITY_1080P);
   } else {
     Gdx.app.log(
         VIDEO_LOGTAG,
         "Current profile is inconsistent, this should never happen on devices with API level 11 or higher! "
             + this.currentProfile);
     prof = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
   }
   return prof;
 }
 private void applyVideoResolution(String resolution) {
   if (resolution.equals("1920x1080")) {
     mContext
         .getSnapManager()
         .setVideoProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_1080P));
   } else if (resolution.equals("1280x720")) {
     mContext
         .getSnapManager()
         .setVideoProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_720P));
   } else if (resolution.equals("720x480")) {
     mContext
         .getSnapManager()
         .setVideoProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_480P));
   } else if (resolution.equals("352x288")) {
     mContext.getSnapManager().setVideoProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_CIF));
   }
 }
示例#12
0
  private void initRecorder() {
    recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);

    CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    recorder.setProfile(cpHigh);
    recorder.setOutputFile("/sdcard/videocapture_example.mp4");
    recorder.setMaxDuration(50000); // 50 seconds
    recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
  }
  @Override
  public void recordVideo(CameraSession session, VideoTransaction xact) throws Exception {
    Descriptor descriptor = (Descriptor) session.getDescriptor();
    Camera camera = descriptor.getCamera();

    if (camera != null) {
      camera.stopPreview();
      camera.unlock();

      try {
        recorder = new MediaRecorder();
        recorder.setCamera(camera);
        recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

        int cameraId = descriptor.getCameraId();
        boolean canGoHigh = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH);
        boolean canGoLow = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW);

        if (canGoHigh && (xact.getQuality() == 1 || !canGoLow)) {
          recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH));
        } else if (canGoLow) {
          recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW));
        } else {
          throw new IllegalStateException("cannot find valid CamcorderProfile");
        }

        recorder.setOutputFile(xact.getOutputPath().getAbsolutePath());
        recorder.setMaxFileSize(xact.getSizeLimit());
        recorder.setMaxDuration(xact.getDurationLimit());
        recorder.setOnInfoListener(this);
        // recorder.setOrientationHint(...);
        recorder.prepare();
        recorder.start();
        this.xact = xact;
      } catch (IOException e) {
        recorder.release();
        recorder = null;
        throw e;
      }
    }
  }
  public CamcorderProfile setCaptureVideoQuality(int cameraType, String captureQuality) {
    Camera camera = _cameras.get(cameraType);
    if (camera == null) {
      return null;
    }

    Camera.Size videoSize = null;
    CamcorderProfile cm = null;
    switch (captureQuality) {
      case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_LOW:
        videoSize = getSmallestSize(getSupportedVideoSizes(camera));
        cm =
            CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_480P);
        break;
      case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_MEDIUM:
        List<Camera.Size> sizes = getSupportedVideoSizes(camera);
        videoSize = sizes.get(sizes.size() / 2);
        cm =
            CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_720P);
        break;
      case RCTCameraModule.RCT_CAMERA_CAPTURE_QUALITY_HIGH:
        videoSize =
            getBestSize(getSupportedVideoSizes(camera), Integer.MAX_VALUE, Integer.MAX_VALUE);
        cm =
            CamcorderProfile.get(_cameraTypeToIndex.get(cameraType), CamcorderProfile.QUALITY_HIGH);
    }

    if (cm == null) {
      return null;
    }

    if (videoSize != null) {
      cm.videoFrameHeight = videoSize.height;
      cm.videoFrameWidth = videoSize.width;
    }

    return cm;
  }
示例#15
0
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  private boolean prepareVideoRecorder() {
    mCamera = tbs.beamr.android.sid.CamHelper.getDefaultCameraInstance();
    final Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
    if (sizes == null || sizes.size() < 1) {
      sizes = parameters.getSupportedVideoSizes();
    }

    Log.e("supported sizes > ", getSizeString(sizes));
    final Camera.Size size = getCameraSize(sizes);

    switch (hasAutoFocus(parameters)) {
      case 0:
        break;
      case 1:
        parameters.set("cam_mode", 1);
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        break;
      case 2:
        parameters.set("cam_mode", 1);
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
        break;
    }

    mCamera.setParameters(parameters);
    try {
      mCamera.setPreviewDisplay(mPreview.getHolder());
    } catch (IOException e) {
      Log.e(TAG, "Surface View is unavailable or unsuitable" + e.getMessage());
      return false;
    }
    mMediaRecorder = new MediaRecorder();

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

    // Step 2: Set sources
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    mMediaRecorder.setOrientationHint(90);

    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    final CamcorderProfile profile =
        CamcorderProfile.get(
            CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)
                ? CamcorderProfile.QUALITY_480P
                : CamcorderProfile.QUALITY_HIGH);
    //        profile.videoFrameRate = 25;
    //            profile.videoBitRate = 7200000;
    mMediaRecorder.setProfile(profile);
    //        if (size == null) {
    //            mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    //            final CamcorderProfile profile =
    // CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
    ////            profile.videoFrameRate = 30;
    ////            profile.videoBitRate = 7200000;
    //            mMediaRecorder.setProfile(profile);
    //        } else {
    //            // Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
    //            if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) {
    //                final CamcorderProfile profile =
    // CamcorderProfile.get(CamcorderProfile.QUALITY_720P);
    //                Log.e("recordingSize > ", String.valueOf(profile.videoFrameWidth) + "x" +
    // String.valueOf(profile.videoFrameHeight));
    //                mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    //                mMediaRecorder.setProfile(profile);
    //            } else {
    //                mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    //                mMediaRecorder.setVideoEncodingBitRate(8200000);
    //                mMediaRecorder.setVideoSize(size.width, size.height);
    ////            mMediaRecorder.setVideoFrameRate(20);
    //                mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
    //            }
    //        }

    // Step 4: Set output file
    // Todo
    //        final String name = Environment.getExternalStorageDirectory().getAbsolutePath() +
    // "/tbs_beamR/received_file_" + (new Date(System.currentTimeMillis())).toString() + ".mp4";
    final String name =
        Environment.getExternalStorageDirectory().getAbsolutePath() + "/test/test.mp4";
    final File file = new File(name);
    if (!file.exists()) {
      try {
        file.getParentFile().mkdirs();
        //                file.createNewFile();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    mMediaRecorder.setOutputFile(name);

    // Step 5: Prepare configured MediaRecorder
    try {
      mMediaRecorder.prepare();
    } catch (IllegalStateException e) {
      Log.e(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    } catch (IOException e) {
      Log.e(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
      releaseMediaRecorder();
      return false;
    }
    return true;
  }
  private boolean prepareMediaRecorder(int forceQuality) {
    try {
      final Activity activity = getActivity();
      if (null == activity) return false;
      final BaseCaptureInterface captureInterface = (BaseCaptureInterface) activity;

      setCameraDisplayOrientation(mCamera.getParameters());
      mMediaRecorder = new MediaRecorder();
      mCamera.stopPreview();
      mCamera.unlock();
      mMediaRecorder.setCamera(mCamera);

      Log.d(
          "Camera1Fragment",
          String.format(
              "Bit rate: %d, Frame rate: %d, Resolution: %s",
              captureInterface.videoBitRate(),
              captureInterface.videoFrameRate(),
              String.format(Locale.getDefault(), "%dx%d", mVideoSize.width, mVideoSize.height)));

      mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
      mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
      CamcorderProfile camcorderProfile = CamcorderProfile.get(getCurrentCameraId(), forceQuality);
      camcorderProfile.videoBitRate = 1024000;
      mMediaRecorder.setProfile(camcorderProfile);
      mMediaRecorder.setVideoSize(mVideoSize.width, mVideoSize.height);
      if (captureInterface.videoFrameRate() > 0)
        mMediaRecorder.setVideoFrameRate(captureInterface.videoFrameRate());
      if (captureInterface.videoBitRate() > 0)
        mMediaRecorder.setVideoEncodingBitRate(captureInterface.videoBitRate());
      Uri uri = Uri.fromFile(getOutputMediaFile());
      mOutputUri = uri.toString();
      mMediaRecorder.setOutputFile(uri.getPath());

      mMediaRecorder.setOrientationHint(mDisplayOrientation);
      mMediaRecorder.setPreviewDisplay(mPreviewView.getHolder().getSurface());

      try {
        mMediaRecorder.prepare();
        return true;
      } catch (Throwable e) {
        throwError(new Exception("Failed to prepare the media recorder: " + e.getMessage(), e));
        return false;
      }
    } catch (Throwable t) {
      try {
        mCamera.lock();
      } catch (IllegalStateException e) {
        throwError(new Exception("Failed to re-lock camera: " + e.getMessage(), e));
        return false;
      }
      if (forceQuality == CamcorderProfile.QUALITY_480P)
        return prepareMediaRecorder(CamcorderProfile.QUALITY_720P);
      else if (forceQuality == CamcorderProfile.QUALITY_720P)
        return prepareMediaRecorder(CamcorderProfile.QUALITY_LOW);
      else if (forceQuality == CamcorderProfile.QUALITY_LOW) {
        return prepareMediaRecorder(CamcorderProfile.QUALITY_1080P);
      }
      throwError(new Exception("Failed to begin recording: " + t.getMessage(), t));
      return false;
    }
  }
 private static int getVideoCaptureDurationLimit() {
   CamcorderProfile camcorder = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
   return camcorder == null ? 0 : camcorder.duration;
 }