一、依赖implementation 'com.danikula:videocache:2.7.1'
二、新建类VideoCache
public class VideoCache extends Application {
public HttpProxyCacheServer proxy;
public static HttpProxyCacheServer getProxy(Context context) {
VideoCache app = (VideoCache) context.getApplicationContext();
return app.proxy == null ? (app.proxy = app.newProxy()) : app.proxy;
}
public HttpProxyCacheServer newProxy() {
return new HttpProxyCacheServer.Builder(this)
.maxCacheSize(1024*1024*1024) //1G缓存空间
.maxCacheFilesCount(10) //最大文件数
.build();
}
}
三、AndroidManifest
中application
标签添加/修改android:name=".VideoCache"
四、VideoView
设置资源路径时setVideoPath(getProxy(this).getProxyUrl(网络资源链接))