一个关于MediaRecorder.setMaxDuration()的问题

void android.media.MediaRecorder.setMaxDuration(int max_duration_ms) throws IllegalArgumentException

Sets the maximum duration (in ms) of the recording session. Call this after setOutFormat() but before prepare(). After recording reaches the specified duration, a notification will be sent to the android.media.MediaRecorder.OnInfoListener with a "what" code of MEDIA_RECORDER_INFO_MAX_DURATION_REACHED and recording will be stopped. Stopping happens asynchronously, there is no guarantee that the recorder will have stopped by the time the listener is notified.
google这里解释的最后一句话的意思大概是当监听被通知的时候不能保证recorder已经完成了,不理解,既然这个监听是不准的, 那我要这个还有卵用? 我要实现的功能很简单,就是类似微信的一样Camera拍摄15s的视频之后停止,我要监听Camera什么时候真正完成录制视频了。

阅读 7.5k
1 个回答
新手上路,请多包涵
 mediarecorder.setMaxDuration(10000);//10s
 mediarecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
                    @Override
                    public void onInfo(MediaRecorder mr, int what, int extra) {
                        if(what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED){
                            stopVideo();
                        }
                    }
                });

添加监听器就好了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题