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

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

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

MediaRecorder.setPreviewDisplay介绍

暂无

代码示例

代码示例来源: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 testPreviewDisplay() throws Exception {
 assertThat(shadowMediaRecorder.getState()).isNotEqualTo(ShadowMediaRecorder.STATE_DATA_SOURCE_CONFIGURED);
 assertThat(shadowMediaRecorder.getPreviewDisplay()).isNull();
 Surface surface = Shadow.newInstanceOf(Surface.class);
 mediaRecorder.setPreviewDisplay(surface);
 assertThat(shadowMediaRecorder.getPreviewDisplay()).isNotNull();
 assertThat(shadowMediaRecorder.getPreviewDisplay()).isSameAs(surface);
 assertThat(shadowMediaRecorder.getState()).isEqualTo(ShadowMediaRecorder.STATE_DATA_SOURCE_CONFIGURED);
}

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

mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
mrec.setPreviewDisplay(surfaceHolder.getSurface());
mrec.setOutputFile("/sdcard/zzzz.3gp");

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

camera.unlock();
mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
mediaRecorder.setCamera(camera);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);

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

recorder.setPreviewDisplay(holder.getSurface());

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

videoRecorder.setPreviewDisplay(surface);

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

mMediaRecorder.setPreviewDisplay(surface);

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

mediaRecorder.setMaxFileSize(50000000); // Set max file size 50Mb
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
  mediaRecorder.setOrientationHint(VideoWithSurfaceVw.orientation);
  try {

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

recorder.setPreviewDisplay(holder.getSurface());

代码示例来源:origin: qq542391099/CameraSurfaceView-master

public void stopRecord() {
  if (!isRecording) return;
  mediaRecorder.setPreviewDisplay(null);
  try {
    mediaRecorder.stop();
    isRecording = false;
    Toast.makeText(context, "视频已保存在根目录", Toast.LENGTH_SHORT).show();
  } catch (IllegalStateException e) {
    e.printStackTrace();
  }
}

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

private void prepareRecorder(SurfaceHolder holder) {
 mediaRecorder.setPreviewDisplay(holder.getSurface());
 try {
  mediaRecorder.prepare();
 } catch (Exception e) {
  LogUtil.log.e("failed to prepare MediaRecorder. cause: ", e);
 }
}

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

private void prepareRecorder() {
  recorder.setPreviewDisplay(holder.getSurface());
  try {
    recorder.prepare();
    isPrepare = true;
  } catch (IllegalStateException e) {
    e.printStackTrace();
    finish();
  } catch (IOException e) {
    e.printStackTrace();
    finish();
  }
}

代码示例来源:origin: sxpl/FaceAC

/**
 * 停止录制
 */
public void stopRecord() {
  if (mMediaRecorder != null) {
    // 设置后不会崩
    this.mMediaRecorder.setOnErrorListener(null);
    this.mMediaRecorder.setOnInfoListener(null);
    this.mMediaRecorder.setPreviewDisplay(null);
    try {
      this.mMediaRecorder.stop();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (RuntimeException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

代码示例来源:origin: sxpl/FaceAC

/**
 * 释放资源
 */
public void releaseRecord() {
  if (this.mMediaRecorder != null) {
    this.mMediaRecorder.setOnErrorListener(null);
    this.mMediaRecorder.setOnErrorListener(null);
    this.mMediaRecorder.setOnInfoListener(null);
    this.mMediaRecorder.setPreviewDisplay(null);
    try {
      mMediaRecorder.release();
    } catch (IllegalStateException e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  this.mMediaRecorder = null;
}

代码示例来源:origin: Gentleman-jun/VideoRecordDemo

/**
 * 停止录制视频
 */
public void stopRecord() {
  // 设置后不会崩
  mediaRecorder.setOnErrorListener(null);
  mediaRecorder.setPreviewDisplay(null);
  //停止录制
  mediaRecorder.stop();
  mediaRecorder.reset();
  //释放资源
  mediaRecorder.release();
  mediaRecorder = null;
}

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

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();

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

Socket socket = new Socket(serverAddr, serverPort);
socket.setTcpNoDelay(true);
ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);
Camera camera = Camera.open();
camera.unlock();
MediaRecorder recorder = new MediaRecorder();
recorder.setCamera(camera);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H263);
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
recorder.setVideoFrameRate(15);
recorder.setVideoSize(480, 320);
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: stackoverflow.com

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
recorder.setVideoSize(720,480);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
recorder.setOutputFile(PATH_TO_FILE);
recorder.setPreviewDisplay(holder.getSurface());
recorder.prepare();

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

public class VideoHolderCallback implements SurfaceHolder.Callback{
MediaRecorder recorder;
...
public void configureRecorder(){

  if(camera == null) {
    camera = Camera.open();
    camera.unlock();
  }
  recorder.setCamera(camera);
  recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
  recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
  recorder.setOutputFile(filePath);
  recorder.setPreviewDisplay(holder.getSurface());
  recorder.prepare();
}

相关文章