android - 如何删除 ExoPlayer 中的所有下载和动作文件
问题描述
我正在使用 SimpleCache 存储我通过 ExoPlayer 的 DownloadService 下载的 Dash 块,这些块存储在文件夹 DOWNLOAD_CONTENT_DIRECTORY 中。我的 DownloadManager 还将 DownloadActions 保存在文件夹 DOWNLOAD_ACTION_FILE 中。我想从磁盘中清除所有与下载相关的文件。我能想到的最简单的解决方案是直接删除存储在这些目录中的所有文件,但我不知道这是否是在不影响 ExoPlayer 中其他任何内容的情况下这样做的正确方法。我认为的另一种方法是为我拥有的每个下载调用 DownloadService.startWithAction(removeDownloadAction),但在这种情况下,我想不加选择地删除所有下载。
public Cache getDownloadCache(Context context) {
if (downloadCache == null) {
File downloadContentDirectory = new File(getDownloadDirectory(context), DOWNLOAD_CONTENT_DIRECTORY);
downloadCache = new SimpleCache(downloadContentDirectory, new NoOpCacheEvictor());
}
return downloadCache;
}
public File getDownloadDirectory(Context context) {
File downloadDirectory = context.getExternalFilesDir(null);
if (downloadDirectory == null) {
downloadDirectory = context.getFilesDir();
}
return downloadDirectory;
}
这就是我创建我的 DownlodManager 的方式
private synchronized void initDownloadManager() {
if (downloadManager == null) {
DownloaderConstructorHelper downloaderConstructorHelper =
new DownloaderConstructorHelper(getDownloadCache(this), DataSourceUtil.buildHttpDataSourceFactory(this));
downloadManager =
new DownloadManager(
downloaderConstructorHelper,
MAX_SIMULTANEOUS_DOWNLOADS,
DownloadManager.DEFAULT_MIN_RETRY_COUNT,
new File(getDownloadDirectory(this), DOWNLOAD_ACTION_FILE));
}
}
解决方案
推荐阅读
- angular - 测量外部 API 调用的时间:以角度处理异步
- angular - 学习 Angular 以及决定主屏幕 html 的因素
- redis - 在 Redis 中提高写入性能的选项
- python - 从数据库访问与时间戳对应的值会返回一个 Series 而不是单个 numpy.float64 值
- php - 如何在单个 cURL 请求中获取和发布信息?
- kubernetes - Kubernetes pod 无法解析主机?
- php - 我目前遇到 PHP 致命错误的问题
- c# - 将 web-API 注册字段从电子邮件更改为电话号码
- cytoscape.js - Cytoscape 链接删除支持
- python - ANTLR4 python 语法错误与设置示例