如何暂停/恢复使用 mediarecorder 创建的录音?
我正在尝试暂停来电录音并稍后恢复。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题的简单答案是不,您不能
一旦您录制,唯一可能的操作就是停止和重置。
因此,请尝试在停止后将您的呼叫保存到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.