Pause and Resume Audio recording in Android

2019-01-23 08:27发布

问题:

I am developing an audio recording application in Android 2.3 using MediaRecorder class. I have the following requirement :

  1. When an interruption occurs , say during recording a call occurs , pause recording .
  2. After the interruption is over and onResume of my recording activity is called , i have to resume recording from the point where it was paused .

I could not find any MediaRecorder api to pause and resume recording . Only start() and stop() are available.
Apart from recording two separate files before and after interruption and then joining then together into one file ,is there any other way to achieve this ?
Any help/suggestion would be greatly appreciated .

Sneha John.

回答1:

There are two possible ways to do this task, if u are using media recorder for the recording than you can append one audio file into another, Like when you got a incoming call than automatically your on pause is called and on your onPause() you can recorde that 1st file, when you comes back again on your activity than you can record a temporary fileResume() and append this temporary file into the previous one.

And another way is using AudioRecorder() class. In that you can record audio as raw file and append those files as per your requirement and finally when you want to stop the recording than add a header into that raw file and convert that into your desired audio format.



回答2:

This link may useful for you.

https://github.com/lassana/continuous-audiorecorder