List of usage examples for android.media CamcorderProfile get
public static CamcorderProfile get(int quality)
From source file:Main.java
public static String convertOutputFormatToFileExt() { CamcorderProfile camcorderProfile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); if (camcorderProfile.fileFormat == MediaRecorder.OutputFormat.MPEG_4) { return ".mp4"; }// w w w .j a v a 2s . c o m return ".3gp"; }
From source file:com.example.android.mediarecorder.MainActivity.java
private boolean preparePreview() { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { try {//w w w. j av a 2 s . co m CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); String id = manager.getCameraIdList()[0]; CameraCharacteristics characteristics = manager.getCameraCharacteristics(id); sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); } catch (CameraAccessException e) { Log.e("ERROR", "Cannot access Camera2 API"); e.printStackTrace(); } } Log.i(TAG, "Preparing Camera Preview"); // BEGIN_INCLUDE (configure_preview) // mCamera = CameraHelper.getDefaultCameraInstance(); // We need to make sure that our preview and recording video size are supported by the // camera. Query camera to find all the sizes and choose the optimal size given the // dimensions of our preview surface. Camera.Parameters parameters = mCamera.getParameters(); List<Camera.Size> mSupportedPreviewSizes = parameters.getSupportedPreviewSizes(); List<Camera.Size> mSupportedVideoSizes = parameters.getSupportedVideoSizes(); Camera.Size optimalSize = CameraHelper.getOptimalVideoSize(mSupportedVideoSizes, mSupportedPreviewSizes, mPreview.getWidth(), mPreview.getHeight()); // Use the same size for recording profile. CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); profile.videoFrameWidth = optimalSize.width; profile.videoFrameHeight = optimalSize.height; // likewise for the camera object itself. parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight); mCamera.setParameters(parameters); try { // Requires API level 11+, For backward compatibility use {@link setPreviewDisplay} // with {@link SurfaceView} // mCamera.setPreviewTexture(mPreview.getSurfaceTexture()); mHolder = mPreview.getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // mHolder.setKeepScreenOn(true); setCameraDisplayOrientation(0); mCamera.setPreviewDisplay(mPreview.getHolder()); mCamera.startPreview(); Log.i(TAG, "Setting Preview Display"); } catch (IOException e) { Log.e(TAG, "Surface texture is unavailable or unsuitable" + e.getMessage()); return false; } // END_INCLUDE (configure_preview) return true; }
From source file:com.example.android.mediarecorder.MainActivity.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private boolean prepareVideoRecorder() { if (!preparePreview()) { return false; }/*from w ww.j a va 2 s.com*/ CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); // BEGIN_INCLUDE (configure_media_recorder) mMediaRecorder = new MediaRecorder(); // Step 1: Unlock and set camera to MediaRecorder mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) mMediaRecorder.setProfile(profile); // orientation int rotation = getWindowManager().getDefaultDisplay().getRotation(); Log.i("TESTING", "Sensor Orientation: " + sensorOrientation); if (sensorOrientation == SENSOR_ORIENTATION_DEFAULT_DEGREES) { Log.i("TESTING", "Recorder: DEFAULT ROTATION: " + DEFAULT_ORIENTATIONS.get(rotation)); mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation)); } else { Log.i("TESTING", "Recorder: INVERSING ROTATION: " + INVERSE_ORIENTATIONS.get(rotation)); mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation)); } // Step 4: Set output file mOutputFile = CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO); if (mOutputFile == null) { return false; } mMediaRecorder.setOutputFile(mOutputFile.getPath()); // END_INCLUDE (configure_media_recorder) // 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; }
From source file:com.czh.testmpeg.videorecord.CameraActivity.java
private boolean prepareMediaRecorder() { mediaRecorder = new MediaRecorder(); mCamera.unlock();// w ww .ja v a 2s . co m mediaRecorder.setCamera(mCamera); mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { if (cameraFront) { mediaRecorder.setOrientationHint(270); } else { mediaRecorder.setOrientationHint(90); } } mediaRecorder.setProfile(CamcorderProfile.get(quality)); File file = new File("/mnt/sdcard/videokit"); if (!file.exists()) { file.mkdirs(); } Date d = new Date(); String timestamp = String.valueOf(d.getTime()); // url_file = Environment.getExternalStorageDirectory().getPath() + "/videoKit" + timestamp + ".mp4"; url_file = "/mnt/sdcard/videokit/in.mp4"; // url_file = "/mnt/sdcard/videokit/" + timestamp + ".mp4"; File file1 = new File(url_file); if (file1.exists()) { file1.delete(); } mediaRecorder.setOutputFile(url_file); // https://developer.android.com/reference/android/media/MediaRecorder.html#setMaxDuration(int) ?? // mediaRecorder.setMaxDuration(CameraConfig.MAX_DURATION_RECORD); // 60s. // https://developer.android.com/reference/android/media/MediaRecorder.html#setMaxFileSize(int) ?? // mediaRecorder.setMaxFileSize(CameraConfig.MAX_FILE_SIZE_RECORD); //size 1G try { mediaRecorder.prepare(); } catch (IllegalStateException e) { e.printStackTrace(); releaseMediaRecorder(); return false; } catch (IOException e) { e.printStackTrace(); releaseMediaRecorder(); return false; } return true; }
From source file:com.android.mms.ui.MessageUtils.java
public static int getVideoCaptureDurationLimit() { CamcorderProfile camcorder = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW); return camcorder == null ? 0 : camcorder.duration; }