CacheVideoByUrlActivity.java
2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.cnlive.demo.video.cache;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import com.cnlive.libs.video.cache.CacheManager;
import com.cnlive.libs.video.cache.ICache;
import com.cnlive.libs.video.cache.ProxyService;
/**
* Created by gujun on 2017/10/20.
*/
public class CacheVideoByUrlActivity extends VideoActivity {
private static final String TAG = "CacheVideoByUrlActivity";
private ProxyService proxyService;
private String url;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
private void init() {
url = getIntent().getStringExtra("url");
proxyService = CacheManager.getProxyService(this);
int cachePercent = proxyService.getCachingPercent(url);
setVideoSecondaryProgress(cachePercent);
//开启缓存后才能使用此地址播放
String playerUrl = proxyService.getProxyUrl(url);
proxyService.registerCacheStatusListener(mCacheStatusListener, url);
proxyService.registerErrorListener(mOnErrorListener);
proxyService.registerLogEventListener(mOnLogEventListener);
startPlayByUrl(playerUrl);
}
@Override
protected void onDestroy() {
super.onDestroy();
proxyService.unregisterCacheStatusListener(mCacheStatusListener, url);
proxyService.unregisterErrorListener(mOnErrorListener);
proxyService.unregisterLogEventListener(mOnLogEventListener);
}
private ICache.OnCacheStatusListener mCacheStatusListener = new ICache.OnCacheStatusListener() {
@Override
public void OnCacheStatus(String url, long sourceLength, int percentsAvailable) {
Log.e(TAG, "OnCacheStatus: url_" + url + "\nsourceLength:" + sourceLength + "\npercentsAvailable" + percentsAvailable);
if (CacheVideoByUrlActivity.this.url.equals(url)) {
setVideoSecondaryProgress(percentsAvailable);
}
}
};
private ICache.OnErrorListener mOnErrorListener = new ICache.OnErrorListener() {
@Override
public void OnError(int errCode) {
Log.e(TAG, "OnError: " + errCode);
}
};
private ICache.OnLogEventListener mOnLogEventListener = new ICache.OnLogEventListener() {
@Override
public void onLogEvent(String log) {
Log.e(TAG, "onLogEvent: " + log);
}
};
}