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

发布于 2024-12-13 10:06:55 字数 1323 浏览 1 评论 0原文

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

code:

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

I'm trying to pause a recording on an incoming call and resume it later. i'm using the andriod mediarecorder and trying to record in MPEG4. I tried pause/resume with resetting/stopping a recording and starting it with the setOutputFile(fd), fd being the filedescriptor of the audio file that was stopped/paused and hoped it would append but i had no luck. Is there a way to achieve this or append two recordings or should i give up on mediarecorder.

code:

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() stops the recording but resume fails with message start failed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-12-20 10:06:55

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

一旦您录制,唯一可能的操作就是停止和重置。

因此,请尝试在停止后将您的呼叫保存到SDCard,然后再次启动 Fresh Record 并停止它。 最后将两个音频文件合并为一个音频文件

将音频录制为 .wav 文件并使用此格式进行合并

Simple answer for your question is NO YOU CAN'T

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

So try to save your Call to SDCard after you Stop , and then again start Fresh Record and Stop it. Finally Combine both Audio File into one Audio file.

Record the audio as .wav file and Combine using this format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文