List of usage examples for android.hardware.camera2 CameraDevice TEMPLATE_RECORD
int TEMPLATE_RECORD
To view the source code for android.hardware.camera2 CameraDevice TEMPLATE_RECORD.
Click Source Link
From source file:com.example.android.camera2basic.Camera2VideoFragment.java
/** * Start the camera preview.//from w ww. jav a 2 s .co m */ private void startPreview() { Log.d(TAG, "startPreview"); if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return; } try { setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<Surface>(); Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.example.anna_maria.myapplication.Camera2VideoFragment.java
/** * Start the camera preview./* w w w . jav a 2s . c o m*/ */ private void startPreview() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return; } try { setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<Surface>(); Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); } @Override public void onConfigureFailed(CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:wisc.drivesense.vediorecorder.CameraFragment.java
public void startRecordingVideo() { Log.d(TAG, "startRecordingVideo()"); if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//from www.j av a 2s . c o m } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } }
From source file:org.odk.collect.android.fragments.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == cameraDevice || !textureView.isAvailable() || null == previewSize) { return;//from w w w . jav a2s . co m } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = textureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight()); previewBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); previewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder Surface recorderSurface = mediaRecorder.getSurface(); surfaces.add(recorderSurface); previewBuilder.addTarget(recorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording cameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { previewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI isRecordingVideo = true; // Start recording mediaRecorder.start(); ToastUtils.showLongToast( getActivity().getString(R.string.stop_video_capture_instruction)); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { ToastUtils.showShortToast("Failed"); } } }, backgroundHandler); } catch (CameraAccessException | IOException e) { Timber.e(e); } }
From source file:netlab.fakturk.cam2vidndk.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;// w ww. j a va2s .com } try { sensorValue(); closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setText(R.string.stop); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.android.rahul.myselfieapp.Fragment.CamVideoFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;/*w ww . j ava2 s. c o m*/ } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setText(R.string.stop); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.pvjunkies.fieldcam.CameraFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//from w ww . ja va 2s .co m } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setText(R.string.stop); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException | IOException e) { e.printStackTrace(); } }
From source file:me.brandonyuh.secretrecord.Camera2VideoFragment.java
public void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//from w ww . j a v a2 s . c o m } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setText(R.string.stop); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException | IOException e) { e.printStackTrace(); } }
From source file:com.caseystalnaker.android.popinvideodemo.fragments.Camera2VideoFragment.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;//from ww w .j a v a 2 s . com } try { lockOrientation(); closePreviewSession(); setUpMediaRecorder(); final SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview final Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder mRecorderSurface = mMediaRecorder.getSurface(); surfaces.add(mRecorderSurface); mPreviewBuilder.addTarget(mRecorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); startCountdownTimer(); mButtonVideo.setBackgroundDrawable( ContextCompat.getDrawable(mContext, R.drawable.stop_btn)); } }); } @Override public void onConfigureFailed(final @NonNull CameraCaptureSession cameraCaptureSession) { final Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.mebene.ACHud.Camera2VideoFragment2.java
private void startRecordingVideo() { if (null == mCameraDevice || !mTextureView.isAvailable() || null == mPreviewSize) { return;/*from w w w. j a v a2s . co m*/ } try { closePreviewSession(); setUpMediaRecorder(); SurfaceTexture texture = mTextureView.getSurfaceTexture(); assert texture != null; texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_RECORD); List<Surface> surfaces = new ArrayList<>(); // Set up Surface for the camera preview Surface previewSurface = new Surface(texture); surfaces.add(previewSurface); mPreviewBuilder.addTarget(previewSurface); // Set up Surface for the MediaRecorder Surface recorderSurface = mMediaRecorder.getSurface(); surfaces.add(recorderSurface); mPreviewBuilder.addTarget(recorderSurface); // Start a capture session // Once the session starts, we can update the UI and start recording mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession.StateCallback() { @Override public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) { mPreviewSession = cameraCaptureSession; updatePreview(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { // UI mButtonVideo.setText("R.string.stop"); mIsRecordingVideo = true; // Start recording mMediaRecorder.start(); } }); } @Override public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) { Activity activity = getActivity(); if (null != activity) { Toast.makeText(activity, "Failed", Toast.LENGTH_SHORT).show(); } } }, mBackgroundHandler); } catch (CameraAccessException | IOException e) { e.printStackTrace(); } }