Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

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

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()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();
      }
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...