Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - check file size while recording

How can I check video file size while recording using MediaRecorder? And when max file size reached - automatically start recording new video to new file?

Thanks, Michael

like image 805
M. Stefanczuk Avatar asked May 24 '26 15:05

M. Stefanczuk


1 Answers

You can check the file size with:

public long getFileSize(String filepath) {
    File file = new File(filepath);
    if (file.exists())
        return file.length();
    else
        return 0;
}

Call this inside an AsyncTask or Timer, depending on what you want to do with the information, to periodically check the file size and stop the recording and start it again if the max file size is almost reached.

like image 89
The Berga Avatar answered May 27 '26 04:05

The Berga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!