Salman Khakwani
Salman Khakwani

Reputation: 6714

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.

Upvotes: 3

Views: 4185

Answers (2)

plamkata__
plamkata__

Reputation: 763

You can create two instances of MediaRecorder which will overlap slightly (i.e. when the stream is close to the end of the first chunk you can prepare and start the second one). It is possible to record 2 video files using 2 MediaRecorders at the same time if they capture only the video. Unfortunately sharing the mic between 2 MediaRecorder instances is not supported.

Upvotes: 1

Uzair
Uzair

Reputation: 766

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.

Upvotes: 4

Related Questions