I have an app that records audio using MediaRecorder from MIC
whenever a phone call is present, i need to be able to save the last x minutes from this recording when the call is finished - e.g. split the audio file the recording created.
I searched for this and all i could find is how to split a .wav
file by directly deleting bytes from the file. But i am saving the file in:
MediaRecorder.OutputFormat.THREE_GPP
with encoding:
MediaRecorder.OutputFormat.AMR_NB
and I didn't find a way to split this type of file.
This is my code:
public class Recorder
{
private MediaRecorder myRecorder;
public String outputFile = null;
private Context context = null;
public Recorder(Context context_app)
{
context = context_app;
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss", Locale.getDefault());
df.setTimeZone(TimeZone.getDefault());
String time = df.format(new Date());
outputFile = Environment.getExternalStorageDirectory().
getAbsolutePath() + "/"+time+".3gpp"; //this is the folder in which your Audio file willl save
myRecorder = new MediaRecorder();
myRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile(outputFile);
}
public void start() {
try {
myRecorder.prepare();
myRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(context, e.getMessage(),
Toast.LENGTH_SHORT).show();
// prepare() fails
e.printStackTrace();
}
Toast.makeText(context, "Start recording...",
Toast.LENGTH_SHORT).show();
}
public void stop() {
try {
myRecorder.stop();
myRecorder.reset();
myRecorder.release();
myRecorder = null;
Toast.makeText(context, "Stop recording...",
Toast.LENGTH_SHORT).show();
} catch (RuntimeException e) {
// no valid audio/video data has been received
e.printStackTrace();
}
}
}
How can i split the THREE_GPP
by time and save the part I need in a separate file?
Also, i know nothing about manipulating bytes and files directly,so please elaborate if it is the way you solved it.
Thanks in advance