如何暂停/恢复使用 mediarecorder 创建的录音? [英] How to pause/resume a recording created with mediarecorder?

查看:32
本文介绍了如何暂停/恢复使用 mediarecorder 创建的录音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

代码:

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.

pauseRecording() stops the recording but resume fails with message start failed.

推荐答案

简单回答你的问题是NO YOU CAN'T

一旦你开始录制,唯一可能的动作就是停止和重置.

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

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.

将音频录制为 .wav 文件并使用这种格式组合.

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

这篇关于如何暂停/恢复使用 mediarecorder 创建的录音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆