Android MediaRecorder多个文件

我正在使用MediaRecorder从相机录制视频,将其保存为.mp4到SDCard,该SDCard完美无瑕。 我想限制.mp4文件的长度为10秒,然后自动创建一个新文件(即:如果用户记录30秒,我想创建三个文件,segment1.mp4(0:00-0: 10),segment2.mp4(0:10-0:20)和segment3.mp4(0:20-0:30))。

这里是我设置记录器和输出的地方。 录制时应该怎么做才能做到这一点?

private boolean prepareVideoRecorder() {

        this.mMediaRecorder = new MediaRecorder();
        this.mCamera.stopPreview();
        this.mCamera.unlock();
        this.mMediaRecorder.setCamera(mCamera);
        this.mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
        this.mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
        this.mMediaRecorder.setOrientationHint(90);
        this.mMediaRecorder.setMaxDuration(this.VIDEO_CHUNK_LENGTH_MS);  //10,000 ms
        if (getAndroidSDKVersion() >= 8) {
            this.mMediaRecorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
        } else {
            this.mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
            this.mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
            this.mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
        }
        this.mVideoFileName = getOutputMediaFile(MEDIA_TYPE_VIDEO).toString(); // Returns a proper file name
        this.mMediaRecorder.setOutputFile(mVideoFileName);
        this.mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());

        try {
            this.mMediaRecorder.prepare();
        } catch (IllegalStateException e) {
            Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
            this.releaseMediaRecorder();
            return false;
        } catch (IOException e) {
            Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
            this.releaseMediaRecorder();
            return false;
        }
        return true;
    }
链接地址: http://www.djcxy.com/p/5263.html

上一篇: Android MediaRecorder Multiple Files

下一篇: Using android MediaRecorder