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

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

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

MediaRecorder.setAudioEncoder介绍

暂无

代码示例

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

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

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: 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: 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 {
    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");
  }
}

代码示例来源:origin: Piasy/RxAndroidAudio

/**
 * prepare for a new audio record.
 */
@WorkerThread
public synchronized boolean prepareRecord(int audioSource, int outputFormat, int audioEncoder,
    int sampleRate, int bitRate, File outputFile) {
  stopRecord();
  mRecorder = new MediaRecorder();
  mRecorder.setAudioSource(audioSource);
  mRecorder.setOutputFormat(outputFormat);
  mRecorder.setAudioSamplingRate(sampleRate);
  mRecorder.setAudioEncodingBitRate(bitRate);
  mRecorder.setAudioEncoder(audioEncoder);
  mRecorder.setOutputFile(outputFile.getAbsolutePath());
  // Handle IOException
  try {
    mRecorder.prepare();
  } catch (IOException exception) {
    Log.w(TAG, "startRecord fail, prepare fail: " + exception.getMessage());
    setError(ERROR_INTERNAL);
    mRecorder.reset();
    mRecorder.release();
    mRecorder = null;
    return false;
  }
  mState = STATE_PREPARED;
  return true;
}

代码示例来源:origin: Piasy/RxAndroidAudio

stopRecord();
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(audioSource);
mRecorder.setOutputFormat(outputFormat);
mRecorder.setAudioSamplingRate(sampleRate);
mRecorder.setAudioEncodingBitRate(bitRate);
mRecorder.setAudioEncoder(audioEncoder);
mRecorder.setOutputFile(outputFile.getAbsolutePath());
  mRecorder.prepare();
} catch (IOException | RuntimeException exception) {
  Log.w(TAG, "startRecord fail, prepare fail: " + exception.getMessage());
  mRecorder.start();
  mStarted = true;
} catch (RuntimeException exception) {

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

recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats[currentFormat]);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
  recorder.prepare();
  recorder.start();
} catch (IllegalStateException e) {
  e.printStackTrace();

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

setContentView(R.layout.activity_main);
mMediaRecorder = new MediaRecorder();
mMediaRecorder.start();
  mMediaRecorder.prepare();
} catch (Exception e) {
  e.printStackTrace();
int height = mDisplayMetrics.heightPixels;
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(width, height);
mMediaRecorder.setOutputFile(filePath);
mMediaRecorder.start();

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

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

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

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

代码示例来源: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.prepare(); // not properly processed
recorder.start();   // IllegalStateException occurred

相关文章