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

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

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

MediaRecorder.<init>介绍

暂无

代码示例

代码示例来源:origin: ankidroid/Anki-Android

private MediaRecorder initMediaRecorder() {
    MediaRecorder mr = new MediaRecorder();
    mr.setAudioSource(MediaRecorder.AudioSource.MIC);
    mr.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mStatus = Status.INITIALIZED;
    mr.setOutputFile(mAudioPath); // audioPath
                   // could
                   // change
    return mr;
  }
};

代码示例来源:origin: commonsguy/cw-omnibus

void start() {
 recorder=new MediaRecorder();
 recorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
 recorder.setVideoFrameRate(config.frameRate);
 recorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
 recorder.setVideoSize(config.width, config.height);
 recorder.setVideoEncodingBitRate(config.bitRate);
 recorder.setOutputFile(output.getAbsolutePath());
 try {
  recorder.prepare();
  vdisplay=projection.createVirtualDisplay("andcorder",
   config.width, config.height, config.density,
   VIRT_DISPLAY_FLAGS, recorder.getSurface(), null, null);
  beeper.startTone(ToneGenerator.TONE_PROP_ACK);
  recorder.start();
 }
 catch (IOException e) {
  throw new RuntimeException("Exception preparing recorder", e);
 }
}

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

MediaRecorder mRecorder = new MediaRecorder();
File mFile = new File("The output file's absolutePath");

... //config the mRecorder
mRecorder.setOutputFile(mFile.getAbsolutePath());

... //prepare() ...
mRecorder.start();

try {
  mRecorder.stop();
} catch(RuntimeException e) {
  mFile.delete();  //you must delete the outputfile when the recorder stop failed.
} finally {
  mRecorder.release();
  mRecorder = null;
}

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

mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.setOutputFile("/dev/null"); 
mRecorder.prepare();
mRecorder.start();

代码示例来源: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: stackoverflow.com

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
try {
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
  e.printStackTrace();
recorder.start();
recordstarted = true;

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

private SurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mrec = new MediaRecorder();
private Button startRecording = null;
  mrec = new MediaRecorder();  // Works well
  mCamera.unlock();
  mrec.setAudioSource(MediaRecorder.AudioSource.MIC); 
  mrec.setOutputFile("/sdcard/zzzz.3gp"); 
  mrec.prepare();
  mrec.start();

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

final MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setOutputFile(audioPath.toString());
try {
 recorder.prepare();
} catch (Exception e){
  e.printStackTrace();
  recorder.start();
  try {
    Thread.sleep(prefs.getAudioLength());

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

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    .get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
} else {
  recording = true;
  recorder.start();

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

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audioDirTemp + "/audio_file"
    + ".mp3");
  recorder.prepare();
  recorder.start();
  isRecording = true; // we are currently recording
} catch (IllegalStateException e) {

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

mediaRecorder = new MediaRecorder();
camera.unlock();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
mediaRecorder.setOutputFile(
    Environment.getExternalStorageDirectory()+"/"+
    DateFormat.format("yyyy-MM-dd_kk-mm-ss", new Date().getTime())+
);
try { mediaRecorder.prepare(); } catch (Exception e) {}
mediaRecorder.start();

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

@Override
protected boolean prepareVideoRecorder() {
  videoRecorder = new MediaRecorder();
  try {
    videoRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    videoRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    videoRecorder.setOutputFormat(camcorderProfile.fileFormat);
    videoRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
    videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
    videoRecorder.setAudioChannels(camcorderProfile.audioChannels);
    videoRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
    videoRecorder.setAudioEncoder(camcorderProfile.audioCodec);
    videoRecorder.setOutputFile(outputFilePath);
    videoRecorder.prepare();

代码示例来源: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: stackoverflow.com

} else
  mediaRecorder = new MediaRecorder();
  mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);                
  if (!rUncompressed)
    mediaRecorder.setOutputFile(filePath);                    
    mediaRecorder.prepare();
    state = State.READY;
    mediaRecorder = new MediaRecorder();
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  mediaRecorder.start();

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

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
recorder = new MediaRecorder();
initRecorder();
setContentView(R.layout.main);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    .get(CamcorderProfile.QUALITY_HIGH);
recorder.setProfile(cpHigh);
recorder.setOutputFile("/sdcard/videocapture_example.mp4");
recorder.setMaxDuration(50000); // 50 seconds
recorder.setMaxFileSize(5000000); // Approximately 5 megabytes
  recorder.prepare();
} catch (IllegalStateException e) {
  e.printStackTrace();
} else {
  recording = true;
  recorder.start();

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

@Override
protected boolean prepareVideoRecorder() {
  videoRecorder = new MediaRecorder();
  try {
    camera.lock();
    videoRecorder.setCamera(camera);
    videoRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
    videoRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
    videoRecorder.setOutputFormat(camcorderProfile.fileFormat);
    videoRecorder.setVideoFrameRate(camcorderProfile.videoFrameRate);
    videoRecorder.setVideoSize(videoSize.getWidth(), videoSize.getHeight());
    videoRecorder.setAudioChannels(camcorderProfile.audioChannels);
    videoRecorder.setAudioSamplingRate(camcorderProfile.audioSampleRate);
    videoRecorder.setAudioEncoder(camcorderProfile.audioCodec);
    videoRecorder.setOutputFile(outputPath.toString());
    videoRecorder.setPreviewDisplay(surface);
    videoRecorder.prepare();

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

mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFile("/sdcard/myvideo1.mp4");
mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec.
mediaRecorder.setMaxFileSize(50000000); // Set max file size 50Mb
mediaRecorder.setOrientationHint(VideoWithSurfaceVw.orientation);
try {
  mediaRecorder.prepare();
} catch (IllegalStateException e) {
  releaseMediaRecorder();
  mediaRecorder = new MediaRecorder();

代码示例来源:origin: chat-sdk/chat-sdk-android

public File record(String name) {
  stopRecording();
  String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath() + AudioMessageDirectory + File.separator;
  File file = new File(path);
  file.mkdir();
  path += name;
  Timber.v("Recording to: " + path);
  recorder = new MediaRecorder();
  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  recorder.setOutputFile(path);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  try {
    recorder.prepare();
  } catch (IOException e) {
    ChatSDK.logError(e);
  }
  recorder.start();
  startTime = System.currentTimeMillis();
  return new File (path);
}

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

String hostname = "example.com";
int port = 1234;

Socket socket = new Socket(InetAddress.getByName(hostname), port);

ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket);

MediaRecorder recorder = new MediaRecorder();
recorder.setOutputFile(pfd.getFileDescriptor());
recorder.prepare();
recorder.start();

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

MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
if (Build.VERSION.SDK_INT >= 10) {
  recorder.setAudioSamplingRate(44100);
  recorder.setAudioEncodingBitRate(96000);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
} else {
  // older version of Android, use crappy sounding voice codec
  recorder.setAudioSamplingRate(8000);
  recorder.setAudioEncodingBitRate(12200);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
}
recorder.setOutputFile(file.getAbsolutePath());
try {
  recorder.prepare();
} catch (IOException e) {
  throw new RuntimeException(e);
}

相关文章