借助单行代码为任意视频播放器提供缓存支持
因为在流媒体播放时多次下载视频毫无意义!
AndroidVideoCache 只需一行代码即可为你的 VideoView/MediaPlayer、ExoPlayer 或任何其他播放器添加缓存支持!
注意 AndroidVideoCache 仅适用于媒体文件的直链 url,它不支持任何流媒体技术,如 DASH、SmoothStreaming、HLS。
只需添加依赖即可(AndroidVideoCache 已发布在 jcenter 上):
dependencies {
compile 'com.danikula:videocache:2.7.1'
}并使用代理中的 URL 替代原始 URL 来添加缓存:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HttpProxyCacheServer proxy = getProxy();
String proxyUrl = proxy.getProxyUrl(VIDEO_URL);
videoView.setVideoPath(proxyUrl);
}
private HttpProxyCacheServer getProxy() {
// should return single instance of HttpProxyCacheServer shared for whole app.
}为保证正常工作,你应该使用单个 HttpProxyCacheServer 实例
暂无开放 Issues,或尚未同步最近议题。