提交 3a6110b0 编写于 作者: S shuyu

fix #1455

上级 6648391e
......@@ -24,7 +24,9 @@ import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.BindView;
import butterknife.ButterKnife;
......@@ -84,6 +86,8 @@ public class DetailPlayer extends AppCompatActivity {
//初始化不打开外部的旋转
orientationUtils.setEnable(false);
Map<String, String> header = new HashMap<>();
header.put("ee", "33");
GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
gsyVideoOption.setThumbImageView(imageView)
.setIsTouchWiget(true)
......@@ -93,7 +97,8 @@ public class DetailPlayer extends AppCompatActivity {
.setShowFullAnimation(false)
.setNeedLockFull(true)
.setUrl(url)
.setCacheWithPlay(false)
.setMapHeadData(header)
.setCacheWithPlay(true)
.setVideoTitle("测试视频")
.setVideoAllCallBack(new GSYSampleCallBack() {
@Override
......
......@@ -36,10 +36,10 @@ dependencies {
api viewDependencies.ijkplayer_java
api viewDependencies.ijkplayer_exo
api viewDependencies.transitionseverywhere
//api project(':gsyVideoPlayer-proxy_cache')
api project(':gsyVideoPlayer-proxy_cache')
//api project(':gsyVideoPlayer-base')
api "com.shuyu:gsyVideoPlayer-base:$gsyVideoVersion"
api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"
//api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"
// compile fileTree(dir: 'libs', include: ['*.jar'])
......
......@@ -7,21 +7,19 @@ import android.text.TextUtils;
import com.danikula.videocache.CacheListener;
import com.danikula.videocache.HttpProxyCacheServer;
import com.danikula.videocache.file.Md5FileNameGenerator;
import com.danikula.videocache.headers.HeaderInjector;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.utils.FileUtils;
import com.shuyu.gsyvideoplayer.utils.StorageUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
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 {
......@@ -29,7 +27,6 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
//视频代理
protected HttpProxyCacheServer proxy;
protected Map<String, String> mMapHeadData;
protected File mCacheDir;
......@@ -39,8 +36,10 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
private ICacheManager.ICacheAvailableListener cacheAvailableListener;
protected ProxyCacheUserAgentHeadersInjector userAgentHeadersInjector = new ProxyCacheUserAgentHeadersInjector();
/**
* 单例管理器
单例管理器
*/
public static synchronized ProxyCacheManager instance() {
if (proxyCacheManager == null) {
......@@ -60,7 +59,10 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
@Override
public void doCacheLogic(Context context, IMediaPlayer mediaPlayer, String originUrl, Map<String, String> header, File cachePath) {
String url = originUrl;
mMapHeadData = header;
userAgentHeadersInjector.mMapHeadData.clear();
if (header != null) {
userAgentHeadersInjector.mMapHeadData.putAll(header);
}
if (url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) {
HttpProxyCacheServer proxy = getProxy(context.getApplicationContext(), cachePath);
if (proxy != null) {
......@@ -144,7 +146,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
/**
* 创建缓存代理服务,带文件目录的.
创建缓存代理服务,带文件目录的.
*/
public HttpProxyCacheServer newProxy(Context context, File file) {
if (!file.exists()) {
......@@ -152,7 +154,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
HttpProxyCacheServer.Builder builder = new HttpProxyCacheServer.Builder(context);
builder.cacheDirectory(file);
builder.headerInjector(new UserAgentHeadersInjector());
builder.headerInjector(userAgentHeadersInjector);
mCacheDir = file;
return builder.build();
}
......@@ -162,27 +164,16 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
/**
* 创建缓存代理服务
创建缓存代理服务
*/
public HttpProxyCacheServer newProxy(Context context) {
return new HttpProxyCacheServer.Builder(context.getApplicationContext())
.headerInjector(new UserAgentHeadersInjector()).build();
}
/**
* for android video cache header
*/
private class UserAgentHeadersInjector implements HeaderInjector {
@Override
public Map<String, String> addHeaders(String url) {
return (mMapHeadData == null) ? new HashMap<String, String>() : mMapHeadData;
}
.headerInjector(userAgentHeadersInjector).build();
}
/**
* 获取缓存代理服务
获取缓存代理服务
*/
protected static HttpProxyCacheServer getProxy(Context context) {
HttpProxyCacheServer proxy = ProxyCacheManager.instance().proxy;
......@@ -192,7 +183,7 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
/**
* 获取缓存代理服务,带文件目录的
获取缓存代理服务,带文件目录的
*/
public static HttpProxyCacheServer getProxy(Context context, File file) {
......@@ -222,5 +213,4 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
}
}
}
package com.shuyu.gsyvideoplayer.cache;
import com.danikula.videocache.headers.HeaderInjector;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import java.util.HashMap;
import java.util.Map;
/**
for android video cache header
*/
public class ProxyCacheUserAgentHeadersInjector implements HeaderInjector {
public final static Map<String, String> mMapHeadData = new HashMap<>();
@Override
public Map<String, String> addHeaders(String url) {
Debuger.printfLog("****** proxy addHeaders ****** " + mMapHeadData.size());
return mMapHeadData;
}
}
\ No newline at end of file
......@@ -180,6 +180,7 @@ public class HttpUrlSource implements Source {
if (extraHeaders == null) {
return;
}
HttpProxyCacheDebuger.printfError("****** injectCustomHeaders ****** :" + extraHeaders.size());
for (Map.Entry<String, String> header : extraHeaders.entrySet()) {
connection.setRequestProperty(header.getKey(), header.getValue());
}
......
......@@ -40,17 +40,17 @@ dependencies {
//api project(':gsyVideoPlayer-x86_64')
//更多配置版so,增加了concat,rtsp,mpeg,crypto
//api project(':gsyVideoPlayer-ex_so')
api project(':gsyVideoPlayer-ex_so')
//api "com.shuyu:GSYVideoPlayer:$gsyVideoVersion"
//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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册