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

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

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

MediaRecorder.setAudioSource介绍

暂无

代码示例

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

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: 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: commonsguy/cw-omnibus

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
recorder.setOutputFile(getStreamFd());
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setAudioChannels(2);
 recorder.prepare();
 recorder.start();

代码示例来源: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: commonsguy/cw-omnibus

BASENAME);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(output.getAbsolutePath());
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
 recorder.setAudioEncodingBitRate(160 * 1024);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.prepare();
 recorder.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: 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

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: 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

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

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: 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

} 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: 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: 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: 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

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);
}

代码示例来源:origin: dkim0419/SoundRecorder

public void startRecording() {
  setFileNameAndPath();
  mRecorder = new MediaRecorder();
  mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  mRecorder.setOutputFile(mFilePath);
  mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
  mRecorder.setAudioChannels(1);
  if (MySharedPreferences.getPrefHighQuality(this)) {
    mRecorder.setAudioSamplingRate(44100);
    mRecorder.setAudioEncodingBitRate(192000);
  }
  try {
    mRecorder.prepare();
    mRecorder.start();
    mStartingTimeMillis = System.currentTimeMillis();
    //startTimer();
    //startForeground(1, createNotification());
  } catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
  }
}

相关文章