@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public void onResume() { addView(previewStrategy.getWidget()); if (camera == null) { cameraId = getHost().getCameraId(); if (cameraId >= 0) { try { camera = Camera.open(cameraId); if (getActivity().getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) { onOrientationChange.enable(); } setCameraDisplayOrientation(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && getHost() instanceof Camera.FaceDetectionListener) { camera.setFaceDetectionListener((Camera.FaceDetectionListener) getHost()); } } catch (Exception e) { getHost().onCameraFail(FailureReason.UNKNOWN); } } else { getHost().onCameraFail(FailureReason.NO_CAMERAS_REPORTED); } } }
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; } }
public void onPause() { if (camera != null) { previewDestroyed(); removeView(previewStrategy.getWidget()); } lastPictureOrientation = -1; }
void previewCreated() { if (camera != null) { try { previewStrategy.attach(camera); } catch (IOException e) { getHost().handleException(e); } } }