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

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

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

MediaRecorder.setMaxDuration介绍

暂无

代码示例

代码示例来源:origin: guardianproject/haven

private boolean prepare(Camera camera) {
  mCamera = camera;
  mMediaRecorder = new MediaRecorder();
  mCamera.unlock();
  mMediaRecorder.setCamera(mCamera);
  mMediaRecorder.setPreviewDisplay(mHolder.getSurface());
//    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
  mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
 //   mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
  mMediaRecorder.setMaxDuration(mSeconds);
  mMediaRecorder.setOutputFile(mOutputFile);
  try {
    mMediaRecorder.prepare();
  } catch(IllegalStateException e) {
    Log.d("ERROR", "IllegalStateException preparing MediaRecorder: " + e.getMessage());
    releaseMediaRecorder();
    return false;
  } catch (IOException e) {
    Log.d("ERROR", "IOException preparing MediaRecorder: " + e.getMessage());
    releaseMediaRecorder();
    return false;
  }
  return true;
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testMaxDuration() throws Exception {
 assertThat(shadowMediaRecorder.getMaxDuration()).isNotEqualTo(30000);
 mediaRecorder.setMaxDuration(30000);
 assertThat(shadowMediaRecorder.getMaxDuration()).isEqualTo(30000);
}

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

videoRecorder.setMaxDuration(configurationProvider.getVideoDuration());
videoRecorder.setOnInfoListener(this);

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

recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes

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

videoRecorder.setMaxDuration(configurationProvider.getVideoDuration());

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

mMediaRecorder.setMaxDuration(cameraConfigProvider.getVideoDuration());
mMediaRecorder.setOnInfoListener(this);

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

mMediaRecorder.setMaxDuration(cameraConfigProvider.getVideoDuration());

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

mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50Mb

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

recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes

代码示例来源:origin: cn.leancloud.android/avoscloud-push

private void initRecorder() {
 mediaRecorder = new MediaRecorder();
 mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
 mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
 mediaRecorder.setProfile(this.profile);
 mediaRecorder.setOutputFile(this.localPath);
 mediaRecorder.setMaxDuration(this.maxDuration); // seconds
 mediaRecorder.setMaxFileSize(this.maxFileSize); // Approximately 5 megabytes
 SurfaceHolder holder = this.surfaceView.getHolder();
 holder.addCallback(this);
 holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

代码示例来源:origin: CooLoongWu/CoolChat

private void init() {
  //如果文件夹不创建的话那么执行到recorder.prepare()就会报错
  File dir = new File(audioPath);
  if (!dir.exists()) {
    dir.mkdirs();
  }
  recorder = new MediaRecorder();
  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  recorder.setMaxDuration(MAX_LENGTH);
  recorder.setOutputFile(audioFileName);
  try {
    recorder.prepare();
  } catch (IOException e) {
    e.printStackTrace();
    LogUtils.e("MediaRecorder prepare()报错");
  }
}

代码示例来源:origin: mgdbaby/VoiceLine-master

mMediaRecorder.setMaxDuration(1000 * 60 * 10);
try {
  mMediaRecorder.prepare();

代码示例来源:origin: XiqingLiu/RecordView

mMediaRecorder.setMaxDuration(MAX_LENGTH);
mMediaRecorder.prepare();

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

MediaRecorder mediaRecorder = new MediaRecorder(); 
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
 CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH);
mediaRecorder.setProfile(camcorderProfile_HQ);
 mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
 mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec. 
mediaRecorder.setMaxFileSize(5000000); // Set max file size 5M

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

Camera mCamera = getCameraInstance();
 // adjust the camera the way you need
 mCamera.setDisplayOrientation(90);
 MediaRecorder recorder = new MediaRecorder();
 recorder.setCamera(mCamera);
 recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
 recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
 recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
 recorder.setOutputFile(filePath);
 // add any limits
 recorder.setMaxDuration(50000); // 50 seconds
 recorder.setMaxFileSize(5000000); // Approximately 5 megabytes

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

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(PATH_NAME);
recorder.setMaxDuration (DURATION)
recorder.prepare();
recorder.start();

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

private boolean startRecorderInternal() throws Exception {
  shutdownCamera();
  if (!initCamera())
    return false;
  switchCamera.setVisibility(View.GONE);
  mediaRecorder = new MediaRecorder();
  camera.unlock();
  mediaRecorder.setCamera(camera);
  mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  setCamcorderProfile();
  mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
  mediaRecorder.setMaxDuration(1000 * VIDEO_TIMES);
  mediaRecorder.setOutputFile(filename);
  setVideoOrientation();
  mediaRecorder.prepare();
  mediaRecorder.start();
  return true;
}

代码示例来源:origin: nglauber/dominando_android2

private boolean prepararGravacao() {
  abrirCamera();
  mCamera.unlock();
  mMediaRecorder = new MediaRecorder();
  mMediaRecorder.setCamera(mCamera);
  mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
  mMediaRecorder.setOutputFile(mCaminhoArquivo.toString());
  mMediaRecorder.setMaxDuration(60000); // 1 minuto
  mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
    @Override
    public void onInfo(MediaRecorder mr, int what, int extra) {
      if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
        concluirGravacao();
      }
    }
  });
  mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
  try {
    mMediaRecorder.prepare();
  } catch (IOException e) {
    e.printStackTrace();
    liberarMediaRecorder();
    return false;
  }
  return true;
}
private void concluirGravacao() {

代码示例来源: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: QuickBlox/ChatMessagesAdapter-android

private void initMediaRecorder() {
  recorder = new MediaRecorder();
  recorder.setAudioSource(configurationBuilder.audioSource);
  recorder.setOutputFormat(configurationBuilder.outputFormat);
  recorder.setOutputFile(configurationBuilder.filePath);
  recorder.setAudioChannels(configurationBuilder.channels);
  recorder.setAudioEncoder(configurationBuilder.audioEncoder);
  recorder.setAudioEncodingBitRate(configurationBuilder.bitRate);
  recorder.setAudioSamplingRate(configurationBuilder.samplingRate);
  recorder.setMaxDuration(configurationBuilder.duration);
  recorder.setOnInfoListener(new OnInfoListenerImpl());
  recorder.setOnErrorListener(new OnErrorListenerImpl());
}

相关文章