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 takePicture(final PictureTransaction xact) { if (inPreview) { if (isAutoFocusing) { throw new IllegalStateException("Camera cannot take a picture while auto-focusing"); } else { previewParams = camera.getParameters(); Camera.Parameters pictureParams = camera.getParameters(); Camera.Size pictureSize = xact.host.getPictureSize(xact, pictureParams); pictureParams.setPictureSize(pictureSize.width, pictureSize.height); pictureParams.setPictureFormat(ImageFormat.JPEG); if (xact.flashMode != null) { pictureParams.setFlashMode(xact.flashMode); } if (!onOrientationChange.isEnabled()) { setCameraPictureOrientation(pictureParams); } camera.setParameters(xact.host.adjustPictureParameters(xact, pictureParams)); xact.cameraView = this; postDelayed( new Runnable() { @Override public void run() { try { camera.takePicture(xact, null, new PictureTransactionCallback(xact)); } catch (Exception e) { android.util.Log.e(getClass().getSimpleName(), "Exception taking a picture", e); // TODO get this out to library clients } } }, xact.host.getDeviceProfile().getPictureDelay()); inPreview = false; } } else { throw new IllegalStateException( "Preview mode must have started before you can take a picture"); } }