How to pause/resume a recording created with media

2019-01-24 20:44发布

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.

1条回答
Root(大扎)
2楼-- · 2019-01-24 21:38

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.

查看更多
登录 后发表回答