| | |
| | | import com.safeluck.floatwindow.MediaArgu; |
| | | import com.safeluck.floatwindow.ResponseVO; |
| | | import com.safeluck.floatwindow.util.VideoFileUtils; |
| | | import com.safeluck.floatwindow.util.FileUtil; |
| | | |
| | | import timber.log.Timber; |
| | | |
| | |
| | | // 停止当前录像 |
| | | stopCurrentRecording(); |
| | | |
| | | // 通知文件创建 |
| | | // 通知文件创建(当前这段 1 分钟文件) |
| | | if (currentVideoFile != null) { |
| | | notifyCallback(2, 0, currentVideoFile.getName()); |
| | | } |
| | | |
| | | // 开始新的录像 |
| | | |
| | | // 每次写入新文件前,检查并清理存储空间(AnYun_VIDEO 下的 mp4) |
| | | ensureStorageSpaceForMp4(); |
| | | |
| | | // 开始新的录像(创建下一分钟的新文件) |
| | | startRecording(); |
| | | |
| | | // 继续定时 |
| | |
| | | } |
| | | }, RECORD_INTERVAL_MS); |
| | | } |
| | | |
| | | /** |
| | | * 确保存储空间足够(针对 AnYun_VIDEO 下的 mp4) |
| | | * TF 卡:使用 FileUtil.cleanupH264Files(内部已改为清理 mp4)按日期目录删除最早的视频 |
| | | * 内部 Flash:使用 FileUtil.ensureInternalFlashSpaceForH264(内部已改为清理 mp4) |
| | | */ |
| | | private void ensureStorageSpaceForMp4() { |
| | | if (context == null || mediaArgu == null) { |
| | | return; |
| | | } |
| | | try { |
| | | int tfFlag = mediaArgu.getTfCardFlag(); // 0-内部存储,1-TF 卡 |
| | | |
| | | // 先定位当前使用的日期目录,再取其父目录 AnYun_VIDEO 作为根目录 |
| | | File dateDir = VideoFileUtils.getVideoDirectory(context, tfFlag); |
| | | if (dateDir == null) { |
| | | return; |
| | | } |
| | | File rootDir = dateDir.getParentFile(); // .../AnYun_VIDEO |
| | | if (rootDir == null) { |
| | | return; |
| | | } |
| | | |
| | | String rootPath = rootDir.getAbsolutePath(); |
| | | if (tfFlag == 1) { |
| | | // TF 卡:限制总大小 + 剩余空间 |
| | | FileUtil.cleanupH264Files(context, rootPath); |
| | | } else { |
| | | // 内部 Flash:确保剩余空间 ≥ 800MB |
| | | FileUtil.ensureInternalFlashSpaceForH264(context); |
| | | } |
| | | } catch (Exception e) { |
| | | Timber.e(e, "ensureStorageSpaceForMp4 error"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 停止当前录像 |