How can I modify the MediaRecorder source to allow pause/resume recording

473 views Asked by At

Is it possible to modify the MediaRecorder source to allow pause/resume recording? I thought modifying this class was not possible, but recently I was told that it was. The question I have is, why would I want to modify MediaRecorder class and just not extend it and then write additional logic? The basic logic I would add for pausing/resuming recording would go something like this,

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();
} 

The issue with this is that the preview flickers. So I have essentially three questions. Can the source code be modified directly? Is there anything wrong with my approach of extending MediaRecorder? And how can I update my pause/resume to not have the preview flicker? Thanks in advance.

1

There are 1 answers

0
Jiang YD On BEST ANSWER
  1. you can modify the source, the problem is you can not compile the framework source into your apk and replace the framework at runtime. so not to do this.
  2. do you use one file to record every piece? you need record every piece to separated files, or "preview flicker" happen.
  3. if you want to contact all piece to one file, you need record in PCM format(or you need handle file header your self) and make sure the speaker add silence before and after every piece.