The MediaRecorder has an API that lets you automatically chunk the output stream into equally sized files.
For that you have to:
- Call
setMaxFileSizebefore callingpreparewith the maximum size that you want each individual file to be set to - Subscribe to info notifications using
OnInfoListenerand callsetNextOutputFilewhenMEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHINGis reached.
The problem is that although doing everything specified by the documentation, MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING is never triggered and instead MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED is triggered later, after which the MediaRecorder no longer outputs data to any file.
The answer, unfortunately, is that Android's
MediaRecorderAPI forsetMaxFileSizenot fully implemented by all the audio encoders (MPEG-4, AAC, AMR).If we take a close look at their C++ implementations:
We can see that only MPEG-4's implementation notifies the
MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHINGevent: