Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MediaRecorder.setMaxDuration(int timer) what happens when timer expires

Tags:

android

According to the documentation, http://developer.android.com/reference/android/media/MediaRecorder.html#setMaxDuration(int)

the recording stops when the timer expires.

By stop, do they mean it calls internally recorder.stop() and then restores the state the app was in before calling recorder.start()?

like image 785
Namratha Avatar asked Jul 12 '10 09:07

Namratha


2 Answers

I have found that I have to implement MediaRecorder.OnInfoListener and manually stop the recording at that point. Once that is done, the MediaRecorder goes back to the initial state and all of the normal setup has to be done again in order to start recording again.

public class VideoCapture extends Activity implements MediaRecorder.OnInfoListener { 

   public void startVideoRecording() {
      // Normal MediaRecorder Setup
      recorder.setMaxDuration(10000); // 10 seconds
      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();
      }
   }
}
like image 85
vanevery Avatar answered Nov 20 '22 20:11

vanevery


This is handled by OpenCore internally, and the state of the recorder after reaching max duration is uninitialized, as it called stop(). You have setup the recorder again to use it further.

like image 34
ognian Avatar answered Nov 20 '22 19:11

ognian