连续检查外部存储器以进行视频停止录制

时间:2014-02-11 11:24:31

标签: android local-storage android-sdcard mediarecorder

我正在制作视频摄像机应用程序,它将录制视频,但我想在用户内存不足时停止视频录制,因为我将不得不不断检查视频和SD卡的大小

场景是我录制时文件大小会不断变化,所以如何停止在活动中录制视频以及如何连续检查SD卡大小

检查SD卡大小的代码是

StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath());        
            long blockSize = statFs.getBlockSize();
            long totalSize = statFs.getBlockCount()*blockSize;
            long availableSize = statFs.getAvailableBlocks()*blockSize;
            long freeSize = statFs.getFreeBlocks()*blockSize;

            long megAvailablenew = availableSize/ (1024 * 1024);
            Log.e("","Available MB : "+megAvailablenew+" avail "+availableSize)

1 个答案:

答案 0 :(得分:3)

参考这个 -

public long TotalMemory()//Environment.getExternalStorageDirectory().getAbsolutePath()
    {
        StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());   
        long Total = ( (long) statFs.getBlockCount() *  (long) statFs.getBlockSize()) / 1048576;
        return Total;
    }

public long FreeMemory()
{
    StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());
    long Free  = (statFs.getAvailableBlocks() *  (long) statFs.getBlockSize()) / 1048576;
    return Free;
}

public long BusyMemory()
{
    StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath());   
    long Total = ( (long) statFs.getBlockCount() * (long) statFs.getBlockSize()) / 1048576;
    long Free  = (statFs.getAvailableBlocks() *  (long) statFs.getBlockSize()) / 1048576;
    long Busy  = Total - Free;
    return Busy;
}