Exemple #1
0
  public void record() throws Exception {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
      throw new UnsupportedOperationException("Video recording supported only on API Level 11+");
    }

    if (displayOrientation != 0 && displayOrientation != 180) {
      throw new UnsupportedOperationException("Video recording supported only in landscape");
    }

    Camera.Parameters pictureParams = camera.getParameters();

    setCameraPictureOrientation(pictureParams);
    camera.setParameters(pictureParams);

    stopPreview();
    camera.unlock();

    try {
      recorder = new MediaRecorder();
      recorder.setCamera(camera);
      getHost().configureRecorderAudio(cameraId, recorder);
      recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
      getHost().configureRecorderProfile(cameraId, recorder);
      getHost().configureRecorderOutput(cameraId, recorder);
      recorder.setOrientationHint(outputOrientation);
      previewStrategy.attach(recorder);
      recorder.prepare();
      recorder.start();
    } catch (IOException e) {
      recorder.release();
      recorder = null;
      throw e;
    }
  }
Exemple #2
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    setMeasuredDimension(width, height);

    if (width > 0 && height > 0) {
      if (camera != null) {
        Camera.Size newSize = null;

        try {
          if (getHost().getRecordingHint() != CameraHost.RecordingHint.STILL_ONLY) {
            // Camera.Size deviceHint=
            // host.getDeviceProfile()
            // .getPreferredPreviewSizeForVideo(getDisplayOrientation(),
            // width,
            // height,
            // camera.getParameters());

            newSize =
                getHost()
                    .getPreferredPreviewSizeForVideo(
                        getDisplayOrientation(), width, height, camera.getParameters(), null);

            // if (newSize != null) {
            // android.util.Log.wtf("CameraView",
            // String.format("getPreferredPreviewSizeForVideo: %d x %d",
            // newSize.width,
            // newSize.height));
            // }
          }

          if (newSize == null || newSize.width * newSize.height < 65536) {
            newSize =
                getHost()
                    .getPreviewSize(getDisplayOrientation(), width, height, camera.getParameters());
          }
        } catch (Exception e) {
          android.util.Log.e(
              getClass().getSimpleName(), "Could not work with camera parameters?", e);
          // TODO get this out to library clients
        }

        if (newSize != null) {
          if (previewSize == null) {
            previewSize = newSize;
          } else if (previewSize.width != newSize.width || previewSize.height != newSize.height) {
            if (inPreview) {
              stopPreview();
            }

            previewSize = newSize;
            initPreview(width, height, false);
          }
        }
      }
    }
  }
Exemple #3
0
  private void setCameraDisplayOrientation() {
    CameraInfo info = new CameraInfo();
    int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation();
    int degrees = 0;
    DisplayMetrics dm = new DisplayMetrics();

    Camera.getCameraInfo(cameraId, info);
    getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);

    switch (rotation) {
      case Surface.ROTATION_0:
        degrees = 0;
        break;
      case Surface.ROTATION_90:
        degrees = 90;
        break;
      case Surface.ROTATION_180:
        degrees = 180;
        break;
      case Surface.ROTATION_270:
        degrees = 270;
        break;
    }

    if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
      displayOrientation = (info.orientation + degrees) % 360;
      displayOrientation = (360 - displayOrientation) % 360;
    } else {
      displayOrientation = (info.orientation - degrees + 360) % 360;
    }

    boolean wasInPreview = inPreview;

    if (inPreview) {
      stopPreview();
    }

    camera.setDisplayOrientation(displayOrientation);

    if (wasInPreview) {
      startPreview();
    }
  }
Exemple #4
0
 private void previewStopped() {
   if (inPreview) {
     stopPreview();
   }
 }