Maximum File Size

The maximum size of a file captured by MediaRecorder can be specified by passing in the maximum size in bytes to the setMaxFileSize method.

recorder.setMaxFileSize(10000000); // 10 megabytes

To determine when maximum file size has been reached, we need to implement the MediaRecorder.OnInfoListener in our activity and register it with our MediaRecorder. The onInfo method will then be called and the what parameter can be checked against the MediaRecorder.MEDIA_RECORDER_INFO_FILESIZE_REACHED constant. If they match,the maximum file size was reached.

According to the documentation, the MediaRecorder is supposed to stop when the maximum file size is reached, but it seems that it does not do so reliably as of Android 2.2.1. Unfortunately no methods exist for us to check whether it has stopped. In order to actually stop the recording, we must explicitly call the stop method.

Here is some extremely abbreviated code to illustrate.

public class VideoCapture extends Activity implements MediaRecorder.OnInfoListener { public void onCreate(Bundle savedInstanceState) { recorder.setOnInfoListener(this);

public void onInfo(MediaRecorder mr, int what, int extra) {

if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED) { Log.v("VIDEOCAPTURE","Maximum Filesize Reached");

Was this article helpful?

+2 0

Post a comment