I found the solution, you need to use:
MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
Here is full description in Android documentation: MediaRecorder | Android
Below is part of my code which I am using & it is working :)
if(what==MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED)
recorder.stop();
recorder.reset();
// Flag to recording (in my code I am using to stop/start capturing)
recording = false;
recording = true;
initRecorder();
prepareRecorder();
recorder.start();
Toast.makeText(MainActivity.this, "Again",Toast.LENGTH_LONG).show();
// 5 000 ms - 5 s
// 300 000 ms - 5 min
}
To set Max Duration you need to declare:
recorder.setMaxDuration(300000);
in initRecorder()
function.
I recommend you also read this: SetMaxDuration
I hope that what I wrote will help you.