private void setUpSupportedProfiles() { this.qualities = new Array<String>(false, 3); if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) { if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_1080P)) { this.qualities.add(DeviceVideoControl.P1080); } if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) { this.qualities.add(DeviceVideoControl.P720); } if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P)) { this.qualities.add(DeviceVideoControl.P480); } } this.currentProfile = this.qualities.size == 0 ? "" : this.qualities.first(); }
@Override public void recordVideo(CameraSession session, VideoTransaction xact) throws Exception { Descriptor descriptor = (Descriptor) session.getDescriptor(); Camera camera = descriptor.getCamera(); if (camera != null) { camera.stopPreview(); camera.unlock(); try { recorder = new MediaRecorder(); recorder.setCamera(camera); recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA); int cameraId = descriptor.getCameraId(); boolean canGoHigh = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_HIGH); boolean canGoLow = CamcorderProfile.hasProfile(cameraId, CamcorderProfile.QUALITY_LOW); if (canGoHigh && (xact.getQuality() == 1 || !canGoLow)) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_HIGH)); } else if (canGoLow) { recorder.setProfile(CamcorderProfile.get(cameraId, CamcorderProfile.QUALITY_LOW)); } else { throw new IllegalStateException("cannot find valid CamcorderProfile"); } recorder.setOutputFile(xact.getOutputPath().getAbsolutePath()); recorder.setMaxFileSize(xact.getSizeLimit()); recorder.setMaxDuration(xact.getDurationLimit()); recorder.setOnInfoListener(this); // recorder.setOrientationHint(...); recorder.prepare(); recorder.start(); this.xact = xact; } catch (IOException e) { recorder.release(); recorder = null; throw e; } } }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private boolean prepareVideoRecorder() { mCamera = tbs.beamr.android.sid.CamHelper.getDefaultCameraInstance(); final Camera.Parameters parameters = mCamera.getParameters(); List<Camera.Size> sizes = parameters.getSupportedPreviewSizes(); if (sizes == null || sizes.size() < 1) { sizes = parameters.getSupportedVideoSizes(); } Log.e("supported sizes > ", getSizeString(sizes)); final Camera.Size size = getCameraSize(sizes); switch (hasAutoFocus(parameters)) { case 0: break; case 1: parameters.set("cam_mode", 1); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); break; case 2: parameters.set("cam_mode", 1); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO); break; } mCamera.setParameters(parameters); try { mCamera.setPreviewDisplay(mPreview.getHolder()); } catch (IOException e) { Log.e(TAG, "Surface View is unavailable or unsuitable" + e.getMessage()); return false; } mMediaRecorder = new MediaRecorder(); // Step 1: Unlock and set camera to MediaRecorder mCamera.setDisplayOrientation(90); mCamera.unlock(); mMediaRecorder.setCamera(mCamera); // Step 2: Set sources mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); mMediaRecorder.setOrientationHint(90); mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); final CamcorderProfile profile = CamcorderProfile.get( CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_480P) ? CamcorderProfile.QUALITY_480P : CamcorderProfile.QUALITY_HIGH); // profile.videoFrameRate = 25; // profile.videoBitRate = 7200000; mMediaRecorder.setProfile(profile); // if (size == null) { // mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); // final CamcorderProfile profile = // CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH); //// profile.videoFrameRate = 30; //// profile.videoBitRate = 7200000; // mMediaRecorder.setProfile(profile); // } else { // // Step 3: Set a CamcorderProfile (requires API Level 8 or higher) // if (CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)) { // final CamcorderProfile profile = // CamcorderProfile.get(CamcorderProfile.QUALITY_720P); // Log.e("recordingSize > ", String.valueOf(profile.videoFrameWidth) + "x" + // String.valueOf(profile.videoFrameHeight)); // mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); // mMediaRecorder.setProfile(profile); // } else { // mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); // mMediaRecorder.setVideoEncodingBitRate(8200000); // mMediaRecorder.setVideoSize(size.width, size.height); //// mMediaRecorder.setVideoFrameRate(20); // mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); // } // } // Step 4: Set output file // Todo // final String name = Environment.getExternalStorageDirectory().getAbsolutePath() + // "/tbs_beamR/received_file_" + (new Date(System.currentTimeMillis())).toString() + ".mp4"; final String name = Environment.getExternalStorageDirectory().getAbsolutePath() + "/test/test.mp4"; final File file = new File(name); if (!file.exists()) { try { file.getParentFile().mkdirs(); // file.createNewFile(); } catch (Exception e) { e.printStackTrace(); } } mMediaRecorder.setOutputFile(name); // Step 5: Prepare configured MediaRecorder try { mMediaRecorder.prepare(); } catch (IllegalStateException e) { Log.e(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } catch (IOException e) { Log.e(TAG, "IOException preparing MediaRecorder: " + e.getMessage()); releaseMediaRecorder(); return false; } return true; }