如何暂停/恢复使用mediarecorder创建的录音?

时间:2011-11-04 10:14:45

标签: java android append audio-recording mediarecorder

我正在尝试暂停来电的录音并稍后恢复。我正在使用andriod mediarecorder并尝试在MPEG4中录制。我尝试暂停/恢复重置/停止录制,并使用setOutputFile(fd)启动它,fd是已停止/暂停的音频文件的filedescriptor,希望它会附加但是我没有运气。有没有办法实现这个或附加两个录音,或者我应该放弃mediarecorder

private MediaRecorder media_recorder;
private String file_path = null;

public void startRecording(path)
{
  file_path = path
  media_recorder= new MediaRecorder();
  media_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  media_recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  media_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  media_recorder.setOputputFile(path);
  media_recorder.prepare();
}

public void pauseRecording()
{
  media_recorder.stop();
  media_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  media_recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
  media_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  FileOutputStream paused_file = new FileOutputStream(file_path);
  media_recorder.setOutputFile(paused_file.getFD());
}

public void resumeRecording()
{
  media_recorder.prepare();
  media_recorder.start();
}

pauseRecording()停止录制,但恢复失败并显示消息start failed

1 个答案:

答案 0 :(得分:3)

您的问题的简单答案是不,你不能

Once you are recording the only possible actions are stop and reset.

因此,请在停止后尝试将呼叫保存到SDCard,然后再次启动Fresh Record并将其停止。 Finally Combine both Audio File into one Audio file

将音频录制为.wav文件和Combine using this format