Maximum Duration

The maximum duration of a file captured by the MediaRecorder can be set by passing in the maximum duration in milliseconds to the setMaxDuration method.

recorder.setMaxDuration(10000); // 10 seconds

To determine when the maxium duration has been reached, we need to implement the MediaRecorder.OnInfoListener and register it with our MediaRecorder. Then when the duration has been reached, our onInfo method will be triggered, with the what integer being set to the constant MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED.

According to the documentation, the MediaRecorder is supposed to stop when the maximum duration 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 an abbreviated illustration.

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_DURATION_REACHED) { Log.v("VIDEOCAPTURE","Maximum Duration Reached"); mr.stop();

Was this article helpful?

0 0

Post a comment