Search code examples
androidmediarecorderandroid-mediarecordervideo-recording

Recording Videos in Chunks Using Media Recorder Android


I am implementing an Application that includes the functionality of saving Recorded Video in to Different Video Files based on a certain amount of Time.

For Achieving that i have implemented a Custom Camera and used the MediaRecorder.stop() and MediaRecorder.start() in a certain Loop.

But this approach is creating a Lag Effect while restarting Media Recorder (Stop and Start). Is it possible to seamlessly Stop and Start Recording using Media Recorder or any Third Party Library ?

Any help is Highly Appreciated.


Solution

  • I believe the best solution to implement chunks recording is to set maximum time in MediaRecorder Object

    mMediaRecorder.setMaxDuration(CHUNK_TIME);
    

    then you can attach an info listener, it will intimate you when it will hit maximum chunk time

    mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
      @Override
      public void onInfo(MediaRecorder mr, int what, int extra) {
        if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
            // restartVideo()
        }
     }
    });
    

    in restartVideo you should firstly clear previous MediaRecorder Object and start video again.