The MediaRecorder
has an API that lets you automatically chunk the output stream into equally sized files.
For that you have to:
setMaxFileSize
before calling prepare
with the maximum size that you want each individual file to be set toOnInfoListener
and call setNextOutputFile
when MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING
is 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 MediaRecorder
API for setMaxFileSize
not 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_APPROACHING
event:
notify(MEDIA_RECORDER_EVENT_INFO, MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING, 0);