Reputation: 10946
While recording video with Android's MediaRecorder
how to detect and display Toast
message when video file being recorded has reached its maximum size and file is being saved (or is about to be saved)?
EDIT: This is code I currently have but callback is not triggered although file is successfully saved.
final Context activity=this.getBaseContext();
mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
public void onInfo(MediaRecorder mr, int what, int extra) {
// TODO Auto-generated method stub
if(what==MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED)
Toast.makeText(activity, "There is no more space available. Video recording is stopped now.",2000).show();
}
});
// getBytesAvailable() returns bytes available on sdcard
mediaRecorder.setMaxFileSize(getBytesAvailable());
mediaRecorder.prepare();
Upvotes: 3
Views: 2931
Reputation: 51
MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED means the file has reached its maximum size; there may well be more space on the SD card, but something has forbidden the current recording file from growing any larger. This is usually due to a call to MediaRecorder.setMaxFileSize(). If you don't call this method, you won't get the INFO, though you might when the file reaches the 2GB limit of the FAT file system.
I can't find a clear answer as to what happens when you run out of space; some people seem to think onError will be called with what == MEDIA_RECORDER_ERROR_UNKNOWN.
So in other words, call setMaxFileSize() with a size equal to a few seconds of recording. Your callback should work then.
Upvotes: 5