Recording Videos in Chunks Using Media Recorder Android

我的梦境 提交于 2020-01-04 04:18:20

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/25486074/recording-videos-in-chunks-using-media-recorder-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!