android.media.MediaRecorder.setOrientationHint()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.8k)|赞(0)|评价(0)|浏览(278)

本文整理了Java中android.media.MediaRecorder.setOrientationHint()方法的一些代码示例,展示了MediaRecorder.setOrientationHint()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MediaRecorder.setOrientationHint()方法的具体详情如下:
包路径:android.media.MediaRecorder
类名称:MediaRecorder
方法名:setOrientationHint

MediaRecorder.setOrientationHint介绍

暂无

代码示例

代码示例来源:origin: florent37/CameraFragment

videoRecorder.setOnInfoListener(this);
videoRecorder.setOrientationHint(getVideoOrientation(configurationProvider.getSensorPosition()));

代码示例来源:origin: florent37/CameraFragment

videoRecorder.setOrientationHint(getVideoOrientation(configurationProvider.getSensorPosition()));
videoRecorder.setPreviewDisplay(surface);

代码示例来源:origin: willowtreeapps/Hyperion-Android

static void prepare(@NonNull Context context) throws RecordingException {
  mediaRecorder = new MediaRecorder();
  projectionManager = (MediaProjectionManager) context
      .getSystemService(Context.MEDIA_PROJECTION_SERVICE);
  WindowManager windowManager = (WindowManager)
      context.getSystemService(Context.WINDOW_SERVICE);
  displayMetrics = new DisplayMetrics();
  windowManager.getDefaultDisplay().getMetrics(displayMetrics);
  createDirectoryIfNeeded(context);
  String videoId = UUID.randomUUID().toString();
  outputPath = context.getFilesDir().getPath() + "/hyperion_recorder/" + videoId + ".mp4";
  try {
    //mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setOutputFile(outputPath);
    mediaRecorder.setVideoSize(displayMetrics.widthPixels, displayMetrics.heightPixels);
    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    //mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    mediaRecorder.setVideoEncodingBitRate(512 * 2000);
    mediaRecorder.setVideoFrameRate(30);
    int rotation = windowManager.getDefaultDisplay().getRotation();
    int orientation = ORIENTATIONS.get(rotation + 90);
    mediaRecorder.setOrientationHint(orientation);
    mediaRecorder.prepare();
  } catch (IOException e) {
    throw new RecordingException("Failed to initialize the media recorder.", e);
  }
}

代码示例来源:origin: googlesamples/android-Camera2Video

private void setUpMediaRecorder() throws IOException {
  final Activity activity = getActivity();
  if (null == activity) {
    return;
  }
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
    mNextVideoAbsolutePath = getVideoFilePath(getActivity());
  }
  mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
  mMediaRecorder.setVideoEncodingBitRate(10000000);
  mMediaRecorder.setVideoFrameRate(30);
  mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  switch (mSensorOrientation) {
    case SENSOR_ORIENTATION_DEFAULT_DEGREES:
      mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
      break;
    case SENSOR_ORIENTATION_INVERSE_DEGREES:
      mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
      break;
  }
  mMediaRecorder.prepare();
}

代码示例来源:origin: guoxiaoxing/phoenix

mMediaRecorder.setOnInfoListener(this);
mMediaRecorder.setOrientationHint(getVideoOrientation(cameraConfigProvider.getSensorPosition()));

代码示例来源:origin: guoxiaoxing/phoenix

mMediaRecorder.setOrientationHint(getVideoOrientation(cameraConfigProvider.getSensorPosition()));
mMediaRecorder.setPreviewDisplay(surface);

代码示例来源:origin: stackoverflow.com

mediaRecorder.setOrientationHint(VideoWithSurfaceVw.orientation);
try {
  mediaRecorder.prepare();

代码示例来源:origin: huangfangyi/YiChat

@SuppressLint("NewApi")
private void setVideoOrientation() {
  if (Build.VERSION.SDK_INT >= 9) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    mediaRecorder.setOrientationHint(info.orientation);
  }
}

代码示例来源:origin: tyrex-team/senslogs

/**
 * Start the camera recording process
 *
 * @param videoPath The path where the video will be stored
 */
public void startInternal(String videoPath) {
  mBackgroundThread = new HandlerThread(CAMERA_THREAD);
  mBackgroundThread.start();
  mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
  try {
    CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(
        String.valueOf(CAMERA_LENS));
    Integer sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setAudioSource(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ?
        MediaRecorder.AudioSource.UNPROCESSED : MediaRecorder.AudioSource.CAMCORDER);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFile(videoPath);
    mMediaRecorder.setOrientationHint(sensorOrientation == null ? 0 : sensorOrientation);
    mMediaRecorder.setProfile(CamcorderProfile.get(CAMERA_LENS, mSettings.outputQuality.profile));
    mMediaRecorder.prepare();
    mCameraManager.openCamera(String.valueOf(CAMERA_LENS),
        cameraDeviceStateCallback, mBackgroundHandler);
  } catch (IOException | CameraAccessException | SecurityException e) {
    e.printStackTrace();
  }
}

代码示例来源:origin: zhantong/AndroidCamera-TouchToFocusMeteringZoom

private boolean prepareVideoRecorder() {
  mCamera = getCameraInstance();
  mMediaRecorder = new MediaRecorder();
  mCamera.unlock();
  mMediaRecorder.setCamera(mCamera);
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
  String prefVideoSize = prefs.getString("video_size", "");
  String[] split = prefVideoSize.split("x");
  mMediaRecorder.setVideoSize(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
  mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
  mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
  int rotation = getDisplayOrientation();
  mMediaRecorder.setOrientationHint(rotation);
  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;
}

代码示例来源:origin: GitEliteNovice/CustomCamera

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private void setUpMediaRecorder() throws IOException {
  final Activity activity = getActivity();
  if (null == activity) {
    return;
  }
  Log.d("things called","setUpMediaRecording");
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
    mNextVideoAbsolutePath = getVideoFilePath(getActivity());
  }
  mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
  mMediaRecorder.setVideoEncodingBitRate(10000000);
  mMediaRecorder.setVideoFrameRate(30);
  mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  Log.d("orentataions", String.valueOf(global_orm));
  mMediaRecorder.setOrientationHint(getOrientation(rotation));
  mMediaRecorder.prepare();
}

代码示例来源:origin: mobapptuts/android_camera2_api_video_app

private void setupTimelapse() throws IOException {
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_TIME_LAPSE_HIGH));
  mMediaRecorder.setOutputFile(mVideoFileName);
  mMediaRecorder.setCaptureRate(2);
  mMediaRecorder.setOrientationHint(mTotalRotation);
  mMediaRecorder.prepare();
}

代码示例来源:origin: EzequielAdrianM/Camera2Vision

mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(mDisplayOrientation));
} else {
  mMediaRecorder.setOrientationHint(ORIENTATIONS.get(mDisplayOrientation));

代码示例来源:origin: yangjie10930/OpenGL4Android

private void setUpMediaRecorder() throws IOException {
  final Activity activity = getActivity();
  if (null == activity) {
    return;
  }
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  if (mNextVideoAbsolutePath == null || mNextVideoAbsolutePath.isEmpty()) {
    mNextVideoAbsolutePath = getVideoFilePath(getActivity());
  }
  mMediaRecorder.setOutputFile(mNextVideoAbsolutePath);
  mMediaRecorder.setVideoEncodingBitRate(10000000);
  mMediaRecorder.setVideoFrameRate(30);
  mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
  switch (mSensorOrientation) {
    case SENSOR_ORIENTATION_DEFAULT_DEGREES:
      mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
      break;
    case SENSOR_ORIENTATION_INVERSE_DEGREES:
      mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
      break;
  }
  mMediaRecorder.prepare();
}

代码示例来源:origin: 18Gray/ProCamera

mMediaRecorder.setOrientationHint(DEFAULT_ORIENTATIONS.get(rotation));
  break;
case SENSOR_ORIENTATION_INVERSE_DEGREES:
  mMediaRecorder.setOrientationHint(INVERSE_ORIENTATIONS.get(rotation));
  break;

代码示例来源:origin: chengzichen/KrGallery

protected void configureRecorder(int quality, MediaRecorder recorder) {
  Camera.CameraInfo info = new Camera.CameraInfo();
  Camera.getCameraInfo(cameraInfo.cameraId, info);
  int displayOrientation = getDisplayOrientation(info, false);
  recorder.setOrientationHint(displayOrientation);
  int highProfile = getHigh();
  boolean canGoHigh = CamcorderProfile.hasProfile(cameraInfo.cameraId, highProfile);
  boolean canGoLow = CamcorderProfile.hasProfile(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW);
  if (canGoHigh && (quality == 1 || !canGoLow)) {
    recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, highProfile));
  } else if (canGoLow) {
    recorder.setProfile(CamcorderProfile.get(cameraInfo.cameraId, CamcorderProfile.QUALITY_LOW));
  } else {
    throw new IllegalStateException("cannot find valid CamcorderProfile");
  }
  isVideo = true;
}

代码示例来源:origin: zx391324751/weChatDemo

private void initRecorder() {
  recorder = new MediaRecorder();
  camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
  if (camera != null) {
    camera.setDisplayOrientation(90);//摄像图旋转90度
    camera.unlock();
    recorder.setCamera(camera);
  }
  recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
  recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  recorder.setOrientationHint(90); //旋转90度
  //480的清晰度,相当于高清视频与标清视频之间水准,10秒大概5mb左右
  CamcorderProfile cpHigh = CamcorderProfile.get(CamcorderProfile.QUALITY_480P);
  recorder.setProfile(cpHigh);
  recorder.setOutputFile(VIDEO_PATH); //文件名先随便写吧,毕竟只是demo
  recorder.setMaxDuration(10000); // 10 seconds
  recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
}

代码示例来源:origin: mobapptuts/android_camera2_api_video_app

private void setupMediaRecorder() throws IOException {
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  mMediaRecorder.setOutputFile(mVideoFileName);
  mMediaRecorder.setVideoEncodingBitRate(1000000);
  mMediaRecorder.setVideoFrameRate(30);
  mMediaRecorder.setVideoSize(mVideoSize.getWidth(), mVideoSize.getHeight());
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  mMediaRecorder.setOrientationHint(mTotalRotation);
  mMediaRecorder.prepare();
}

代码示例来源:origin: zx391324751/weChatDemo

private void setUpMediaRecorder() throws IOException {
  mediaRecorder = new MediaRecorder();
  CameraCharacteristics characteristics = null;
  try {
    characteristics = cameraManager.getCameraCharacteristics(cameraId);
  } catch (CameraAccessException e) {
    e.printStackTrace();
  }
  if(characteristics == null)
    return;
  StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
  mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
  mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  if (TextUtils.isEmpty(VIDEO_PATH)) {
    return;
  }
  mediaRecorder.setOutputFile(VIDEO_PATH);
  mediaRecorder.setVideoEncodingBitRate(10000000);
  mediaRecorder.setVideoFrameRate(30);
  size = chooseVideoSize(map.getOutputSizes(MediaRecorder.class));
  mediaRecorder.setVideoSize(size.getWidth(), size.getHeight());
  mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
  mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  int rotation = getWindowManager().getDefaultDisplay().getRotation();
  mediaRecorder.setOrientationHint(ORIENTATIONS.get(rotation));
  mediaRecorder.prepare();
}

代码示例来源:origin: duanhong169/Camera

private void setUpMediaRecorder(MediaRecorderConfigurator configurator) throws IOException {
  if (configurator == null || configurator.useDefaultConfigs()) {
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mediaRecorder.setOutputFile(nextVideoAbsolutePath);
    mediaRecorder.setVideoEncodingBitRate(10000000);
    mediaRecorder.setVideoFrameRate(30);
    mediaRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
    mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  }
  if (configurator != null) {
    configurator.configure(mediaRecorder);
  }
  mediaRecorder.setOrientationHint(Utils.getOrientation(sensorOrientation, currentDeviceRotation));
  mediaRecorder.prepare();
}

相关文章