使用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.

为了实现这一点,我实现了自定义相机并在特定循环中使用了MediaRecorder.stop()MediaRecorder.start().

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

但是这种方法在重新启动Media Recorder(停止和启动)时会产生滞后效果.是否可以使用Media Recorder或任何第三方库无缝地停止和开始记录?

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 ?

高度赞赏任何帮助.

我相信实现块记录的最佳解决方案是在MediaRecorder对象中设置最大时间

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

在restartVideo中,您应该首先清除先前的MediaRecorder对象,然后重新开始视频.

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