Home » Android » android – MediaRecorder alternative to setNextOutputFile prior to Oreo?

android – MediaRecorder alternative to setNextOutputFile prior to Oreo?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am using MediaRecorder API prior to Oreo. Problem I am facing is recording happens on one continues big file if recording goes on for 1 or 2 hours.

Since Oreo (API level 26) MediaRecorder API has introduced setNextOutputFile() which can be useful to record across multiple files without loosing data. Those files can be configured to be of small sizes so that while processing they won’t take much of app memory.

My plan is to use them in following way :

File current;
File nextFile;
// Code to initialize/create these file instances
.
.
.
// Code to initialize/create MediaRecorder insatance which will be in try catch
mRecorder.setOutputFile(currentFileName);
mRecorder.prepare();
mRecorder.setNextOutputFile(nextFile);
.
.
mRecorder.start();
.
.
mRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
      @Override
      public void onInfo(MediaRecorder mr, int infoCode, int extra) {
         Log.e(TAG, "Media recorder info : " + infoCode);
         if (infoCode == MediaRecorder.MEDIA_RECORDER_INFO_NEXT_OUTPUT_FILE_STARTED) {
         String path = getNewUniquePath();
         File nextFile = new File(path); 
         mRecorder.setNextOutputFile(nextFile);
      }
   }
 });
.
.
.
// End of code

This approach will keep on providing next files with fixed small size so that even a recording goes beyond 1 or 2 hours we have small sized file list with no data loss.

Now the major problem here is these are available in Oreo not prior API versions.

Is there any alternative available in prior android versions ?
Will support library be helpful in this scenario ?

How to&Answers: