提交 d30b4525 编写于 作者: G guoshuyu

add FileNameGenerator

上级 c60eb1d8
......@@ -6,6 +6,7 @@ import android.text.TextUtils;
import com.danikula.videocache.CacheListener;
import com.danikula.videocache.HttpProxyCacheServer;
import com.danikula.videocache.file.FileNameGenerator;
import com.danikula.videocache.file.Md5FileNameGenerator;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.utils.FileUtils;
......@@ -18,8 +19,8 @@ import java.util.Map;
import tv.danmaku.ijk.media.player.IMediaPlayer;
/**
代理缓存管理器
Created by guoshuyu on 2018/5/18.
* 代理缓存管理器
* Created by guoshuyu on 2018/5/18.
*/
public class ProxyCacheManager implements ICacheManager, CacheListener {
......@@ -36,12 +37,14 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
private static ProxyCacheManager proxyCacheManager;
private static FileNameGenerator fileNameGenerator;
private ICacheManager.ICacheAvailableListener cacheAvailableListener;
protected ProxyCacheUserAgentHeadersInjector userAgentHeadersInjector = new ProxyCacheUserAgentHeadersInjector();
/**
单例管理器
* 单例管理器
*/
public static synchronized ProxyCacheManager instance() {
if (proxyCacheManager == null) {
......@@ -95,7 +98,10 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
(context.getApplicationContext()).getAbsolutePath();
FileUtils.deleteFiles(new File(path));
} else {
Md5FileNameGenerator md5FileNameGenerator = new Md5FileNameGenerator();
FileNameGenerator md5FileNameGenerator = new Md5FileNameGenerator();
if (ProxyCacheManager.fileNameGenerator != null) {
md5FileNameGenerator = ProxyCacheManager.fileNameGenerator;
}
String name = md5FileNameGenerator.generate(url);
if (cachePath != null) {
String tmpPath = cachePath.getAbsolutePath() + File.separator + name + ".download";
......@@ -148,7 +154,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
/**
创建缓存代理服务,带文件目录的.
* 创建缓存代理服务,带文件目录的.
*/
public HttpProxyCacheServer newProxy(Context context, File file) {
if (!file.exists()) {
......@@ -158,6 +164,9 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
builder.cacheDirectory(file);
builder.maxCacheSize(DEFAULT_MAX_SIZE);
builder.headerInjector(userAgentHeadersInjector);
if (fileNameGenerator != null) {
builder.fileNameGenerator(fileNameGenerator);
}
mCacheDir = file;
return builder.build();
}
......@@ -167,7 +176,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
/**
创建缓存代理服务
* 创建缓存代理服务
*/
public HttpProxyCacheServer newProxy(Context context) {
return new HttpProxyCacheServer.Builder(context.getApplicationContext())
......@@ -176,7 +185,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
/**
获取缓存代理服务
* 获取缓存代理服务
*/
protected static HttpProxyCacheServer getProxy(Context context) {
HttpProxyCacheServer proxy = ProxyCacheManager.instance().proxy;
......@@ -186,7 +195,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
/**
获取缓存代理服务,带文件目录的
* 获取缓存代理服务,带文件目录的
*/
public static HttpProxyCacheServer getProxy(Context context, File file) {
......@@ -216,4 +225,11 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
}
public static void setFileNameGenerator(FileNameGenerator fileNameGenerator) {
ProxyCacheManager.fileNameGenerator = fileNameGenerator;
}
public static void clearFileNameGenerator() {
ProxyCacheManager.fileNameGenerator = null;
}
}
......@@ -50,14 +50,14 @@ dependencies {
//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
//api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
//更多配置版so,增加了concat,rtsp,mpeg,crypto
//api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"
api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册