Skip to content

Commit 3a6110b

Browse files
committed
1 parent 6648391 commit 3a6110b

6 files changed

Lines changed: 51 additions & 34 deletions

File tree

app/src/main/java/com/example/gsyvideoplayer/DetailPlayer.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525

2626
import java.util.ArrayList;
27+
import java.util.HashMap;
2728
import java.util.List;
29+
import java.util.Map;
2830

2931
import butterknife.BindView;
3032
import butterknife.ButterKnife;
@@ -84,6 +86,8 @@ protected void onCreate(Bundle savedInstanceState) {
8486
//初始化不打开外部的旋转
8587
orientationUtils.setEnable(false);
8688

89+
Map<String, String> header = new HashMap<>();
90+
header.put("ee", "33");
8791
GSYVideoOptionBuilder gsyVideoOption = new GSYVideoOptionBuilder();
8892
gsyVideoOption.setThumbImageView(imageView)
8993
.setIsTouchWiget(true)
@@ -93,7 +97,8 @@ protected void onCreate(Bundle savedInstanceState) {
9397
.setShowFullAnimation(false)
9498
.setNeedLockFull(true)
9599
.setUrl(url)
96-
.setCacheWithPlay(false)
100+
.setMapHeadData(header)
101+
.setCacheWithPlay(true)
97102
.setVideoTitle("测试视频")
98103
.setVideoAllCallBack(new GSYSampleCallBack() {
99104
@Override

gsyVideoPlayer-java/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ dependencies {
3636
api viewDependencies.ijkplayer_java
3737
api viewDependencies.ijkplayer_exo
3838
api viewDependencies.transitionseverywhere
39-
//api project(':gsyVideoPlayer-proxy_cache')
39+
api project(':gsyVideoPlayer-proxy_cache')
4040
//api project(':gsyVideoPlayer-base')
4141
api "com.shuyu:gsyVideoPlayer-base:$gsyVideoVersion"
42-
api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"
42+
//api "com.shuyu:gsyvideoplayer-androidvideocache:$gsyVideoVersion"
4343

4444

4545
// compile fileTree(dir: 'libs', include: ['*.jar'])

gsyVideoPlayer-java/src/main/java/com/shuyu/gsyvideoplayer/cache/ProxyCacheManager.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,26 @@
77
import com.danikula.videocache.CacheListener;
88
import com.danikula.videocache.HttpProxyCacheServer;
99
import com.danikula.videocache.file.Md5FileNameGenerator;
10-
import com.danikula.videocache.headers.HeaderInjector;
1110
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
1211
import com.shuyu.gsyvideoplayer.utils.FileUtils;
1312
import com.shuyu.gsyvideoplayer.utils.StorageUtils;
1413

1514
import java.io.File;
1615
import java.io.IOException;
17-
import java.util.HashMap;
1816
import java.util.Map;
1917

2018
import tv.danmaku.ijk.media.player.IMediaPlayer;
2119

2220
/**
23-
* 代理缓存管理器
24-
* Created by guoshuyu on 2018/5/18.
21+
代理缓存管理器
22+
Created by guoshuyu on 2018/5/18.
2523
*/
2624

2725
public class ProxyCacheManager implements ICacheManager, CacheListener {
2826

2927
//视频代理
3028
protected HttpProxyCacheServer proxy;
3129

32-
protected Map<String, String> mMapHeadData;
3330

3431
protected File mCacheDir;
3532

@@ -39,8 +36,10 @@ public class ProxyCacheManager implements ICacheManager, CacheListener {
3936

4037
private ICacheManager.ICacheAvailableListener cacheAvailableListener;
4138

39+
protected ProxyCacheUserAgentHeadersInjector userAgentHeadersInjector = new ProxyCacheUserAgentHeadersInjector();
40+
4241
/**
43-
* 单例管理器
42+
单例管理器
4443
*/
4544
public static synchronized ProxyCacheManager instance() {
4645
if (proxyCacheManager == null) {
@@ -60,7 +59,10 @@ public void onCacheAvailable(File cacheFile, String url, int percentsAvailable)
6059
@Override
6160
public void doCacheLogic(Context context, IMediaPlayer mediaPlayer, String originUrl, Map<String, String> header, File cachePath) {
6261
String url = originUrl;
63-
mMapHeadData = header;
62+
userAgentHeadersInjector.mMapHeadData.clear();
63+
if (header != null) {
64+
userAgentHeadersInjector.mMapHeadData.putAll(header);
65+
}
6466
if (url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) {
6567
HttpProxyCacheServer proxy = getProxy(context.getApplicationContext(), cachePath);
6668
if (proxy != null) {
@@ -144,15 +146,15 @@ public void setCacheAvailableListener(ICacheAvailableListener cacheAvailableList
144146
}
145147

146148
/**
147-
* 创建缓存代理服务,带文件目录的.
149+
创建缓存代理服务,带文件目录的.
148150
*/
149151
public HttpProxyCacheServer newProxy(Context context, File file) {
150152
if (!file.exists()) {
151153
file.mkdirs();
152154
}
153155
HttpProxyCacheServer.Builder builder = new HttpProxyCacheServer.Builder(context);
154156
builder.cacheDirectory(file);
155-
builder.headerInjector(new UserAgentHeadersInjector());
157+
builder.headerInjector(userAgentHeadersInjector);
156158
mCacheDir = file;
157159
return builder.build();
158160
}
@@ -162,27 +164,16 @@ public void setProxy(HttpProxyCacheServer proxy) {
162164
}
163165

164166
/**
165-
* 创建缓存代理服务
167+
创建缓存代理服务
166168
*/
167169
public HttpProxyCacheServer newProxy(Context context) {
168170
return new HttpProxyCacheServer.Builder(context.getApplicationContext())
169-
.headerInjector(new UserAgentHeadersInjector()).build();
170-
}
171-
172-
/**
173-
* for android video cache header
174-
*/
175-
private class UserAgentHeadersInjector implements HeaderInjector {
176-
177-
@Override
178-
public Map<String, String> addHeaders(String url) {
179-
return (mMapHeadData == null) ? new HashMap<String, String>() : mMapHeadData;
180-
}
171+
.headerInjector(userAgentHeadersInjector).build();
181172
}
182173

183174

184175
/**
185-
* 获取缓存代理服务
176+
获取缓存代理服务
186177
*/
187178
protected static HttpProxyCacheServer getProxy(Context context) {
188179
HttpProxyCacheServer proxy = ProxyCacheManager.instance().proxy;
@@ -192,7 +183,7 @@ protected static HttpProxyCacheServer getProxy(Context context) {
192183

193184

194185
/**
195-
* 获取缓存代理服务,带文件目录的
186+
获取缓存代理服务,带文件目录的
196187
*/
197188
public static HttpProxyCacheServer getProxy(Context context, File file) {
198189

@@ -222,5 +213,4 @@ public static HttpProxyCacheServer getProxy(Context context, File file) {
222213
}
223214
}
224215

225-
226216
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.shuyu.gsyvideoplayer.cache;
2+
3+
import com.danikula.videocache.headers.HeaderInjector;
4+
import com.shuyu.gsyvideoplayer.utils.Debuger;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
for android video cache header
11+
*/
12+
public class ProxyCacheUserAgentHeadersInjector implements HeaderInjector {
13+
14+
public final static Map<String, String> mMapHeadData = new HashMap<>();
15+
16+
@Override
17+
public Map<String, String> addHeaders(String url) {
18+
Debuger.printfLog("****** proxy addHeaders ****** " + mMapHeadData.size());
19+
return mMapHeadData;
20+
}
21+
}

gsyVideoPlayer-proxy_cache/src/main/java/com/danikula/videocache/HttpUrlSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ private void injectCustomHeaders(HttpURLConnection connection, String url) {
180180
if (extraHeaders == null) {
181181
return;
182182
}
183+
HttpProxyCacheDebuger.printfError("****** injectCustomHeaders ****** :" + extraHeaders.size());
183184
for (Map.Entry<String, String> header : extraHeaders.entrySet()) {
184185
connection.setRequestProperty(header.getKey(), header.getValue());
185186
}

gsyVideoPlayer/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ dependencies {
4040
//api project(':gsyVideoPlayer-x86_64')
4141

4242
//更多配置版so,增加了concat,rtsp,mpeg,crypto
43-
//api project(':gsyVideoPlayer-ex_so')
43+
api project(':gsyVideoPlayer-ex_so')
4444

4545
//api "com.shuyu:GSYVideoPlayer:$gsyVideoVersion"
4646

4747
//api "com.shuyu:gsyVideoPlayer-java:$gsyVideoVersion"
4848
api "com.shuyu:GSYVideoPlayer-exo2:$gsyVideoVersion"
49-
api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
50-
api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
51-
api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
52-
api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
53-
api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
49+
// api "com.shuyu:gsyVideoPlayer-armv5:$gsyVideoVersion"
50+
// api "com.shuyu:gsyVideoPlayer-armv7a:$gsyVideoVersion"
51+
// api "com.shuyu:gsyVideoPlayer-arm64:$gsyVideoVersion"
52+
// api "com.shuyu:gsyVideoPlayer-x64:$gsyVideoVersion"
53+
// api "com.shuyu:gsyVideoPlayer-x86:$gsyVideoVersion"
5454

5555
//更多配置版so,增加了concat,rtsp,mpeg,crypto
5656
//api "com.shuyu:gsyVideoPlayer-ex_so:$gsyVideoVersion"

0 commit comments

Comments
 (0)