MediaRecorder alternative for setNextOutputFile before Oreo?

I use MediaRecorder API before Oreo. The problem I am facing is that the recording happens on one continuation of a large file if the recording lasts 1 or 2 hours.

Since Oreo (API level 26), the MediaRecorder API introduced setNextOutputFile () , which can be useful for writing across multiple files without data loss. These files can be configured to small sizes, so when processing they do not take up a lot of application memory.

My plan is to use them as follows:

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

, 1 2 , .

, Oreo, API.

, Android? ?

+4

Source: https://habr.com/ru/post/1687605/


All Articles