Skills

GSY Video Cache

Covers caching, cache cleanup, and offline download for GSYVideoPlayer on Android.

Install

npx skills add CarGuo/GSYVideoPlayer --skill gsy-cache-and-download -g -a claude-code -y
Repository
CarGuo/GSYVideoPlayer21.5k
Category
Mobile
Updated
26d ago
License
Apache-2.0
Context cost
Lightabout 669 tokens
Runs scripts
No, instructions only

What it does

边播边缓(AndroidVideoCache 代理)、自定义缓存目录、清理缓存、离线下载至完整文件。

gsy-cache-and-download

概念

  • 缓存(cache):ProxyCacheManager 内部起本地 HTTP 代理,拦截 player 的请求,把响应流一边喂给 player 一边写到本地;文件名是 URL MD5。
  • 下载(download):与缓存共享目录,但一定要走"从头到尾"完整播完才能保证文件可复用为独立 mp4;提前 seek 会造成 range 分片,回放时代理会重新下载缺失段。

开启缓存

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

方式 2:GSYVideoOptionBuilder:

  • setCacheWithPlay(true)
  • setCachePath(File)(可选)

自定义缓存目录

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 里:

  • clearAllCache(Context, File), , 清空整个缓存目录。
  • 内部 HttpProxyCacheServer 单例 lazy 初始化,第一次 doCacheLogic 时才起服务;Application 就绪即可。

ProxyCacheUserAgentHeadersInjector

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

离线下载

三步流程:

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

More in Mobile