Segment video, How to Instead of method mediarecoder#setNextOutputFile

Issue

I wanna segment video using mediaRecorder. I saw the method setNextOutputFile

But my work on API lv 25 only and setNextOutputFile added in Android O, API level 26. My project about recording screen share video.

I used setMaxDuration but my data lossing

Solution

I found the question.
First use the setmaxduration

mMediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
            @Override
            public void onInfo(MediaRecorder mediaRecorder, int i, int i1) {

                if (i >= MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED) {
                    Log.d(TAG,"max duration");

                    //104,904MB ~ 120000000L
                    if (SDCard.getInstance().sdCardSpace() <=50000000L ) {
                        SDCard.getInstance().sortFile();
                    }
                    //note: sometimes crash in mediaRecorder.stop();
                    try {
                        mediaRecorder.stop();
                    }catch (Exception e){
                        Log.d(TAG, "Error  mediaRecorder.stop : " + e);
                    }
                    mediaRecorder.reset();
                    stopScreenShare();
                    initMediaRecord();
                    recordScreen();
                }
            }
        });
        mMediaRecorder.prepare();

To avoid lose some seconds in video or can not replay, must not use media release

mediarecorder.release

Answered By – Jamebes

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published