06 gsy cache and download

From CarGuo/GSYVideoPlayer · View interactive version

06 gsy cache and download is an AI agent skill from the GitHub repository CarGuo/GSYVideoPlayer. 边播边缓(AndroidVideoCache 代理)、自定义缓存目录、清理缓存、离线下载至完整文件。

How to use this skill

Skill file

gsy-cache-and-download

概念

开启缓存

方式 1:setUp(url, true, title) 第二参数 cacheWithPlay=true。

方式 2:GSYVideoOptionBuilder:

自定义缓存目录

File dir = new File(getExternalFilesDir(null), "videoCache");
builder.setCachePath(dir);

若使用不同 CacheManager(例如 Exo),传给 CacheFactory.setCacheManager(...) 前记得也走 setCachePath 或自定义 ICacheManager 实现。

`ICacheManager` API

见 ICacheManager。核心方法:

| 方法 | 说明 |

|---|---|

| doCacheLogic(Context, IMediaPlayer, String url, Map<String,String> headers, File cachePath) | 播放前介入,把 url 换为代理 url |

| clearCache(Context, File cachePath, String url) | 单条清除;url = null 清空整目录 |

| hadCached() | 当前播放是否已"命中"缓存(100% 完成) |

| setCacheAvailableListener(CacheAvailableListener) | 缓存进度回调 |

| release() | 释放代理 |

`ProxyCacheManager` 关键静态方法

在 ProxyCacheManager 里:

`ProxyCacheUserAgentHeadersInjector`

自定义 UA / Cookie / Referer 注入到代理层:见 ProxyCacheUserAgentHeadersInjector。挂到 HttpProxyCacheServer.Builder.headerInjector() 上,或直接用 Map 传给 setUp。

离线下载

三步流程:

  1. 用 HttpProxyCacheServer 单独跑一次预下载(不 attach 到 Player),或直接开一条播放并 setStartAfterPrepared(false) 静默走全长;
  2. 事件 VideoAllCallBack#onAutoComplete 触发 → 缓存文件已完整;
  3. 用 FileUtils 拷贝 / 重命名到业务目录。

Demo:DetailDownloadPlayer(IJK)与 DetailDownloadExoPlayer(Exo)。

不缓存的场景

以下情况 cacheWithPlay 应设 false:

常见坑

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.