3

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.

Pannu
  • 2,547
  • 2
  • 23
  • 29

1 Answers1

3

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.

Community
  • 1
  • 1
Venky
  • 11,049
  • 5
  • 49
  • 66
  • any idea on how to append two m4a files? – Pannu Nov 04 '11 at 12:17
  • @Pannu Did you check the post? – Venky Nov 04 '11 at 12:23
  • Yes, although its helpful I believe its about merging `WAVE/PCM` files. Will not work for `m4a (MPEG-4)`. – Pannu Nov 04 '11 at 12:48
  • @Pannu Upto my knowledge we can Combine only .wav and RAW_AMR format files. – Venky Nov 04 '11 at 12:52
  • well I'm going to port `mEncoder` or `ffmpeg` to android and try merging, seems like a possible solution. – Pannu Nov 06 '11 at 14:10
  • No it kept crashing. My mind boggles when i think how popular android is and still this is impossible. :( – Pannu Jan 05 '15 at 17:28
  • @Pannu, have you found a viable solution to this issue? What can be done to pause/resume from MediaRecorder. Are appending stream data or merging files the only solutions? – portfoliobuilder Jun 11 '15 at 00:19
  • @portfoliobuilder: nope.. I had to create a temp file for each pause and then merge them using a ported mencoder binary to andriod. It makes me sick to look at that code but that's all I've got now. Although there are lot of ports available for ffmpeg. – Pannu Jun 11 '15 at 00:46
  • Just an update. MediaRecorder.pause is coming out soon. – Pannu Jun 12 '15 at 00:06
  • Update came with API 24. Now it's possible to pause and resume recorder. – smiki Jul 13 '17 at 15:01