danikula / danikula/AndroidVideoCache

预加载进不去啊

Aperta
#296 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Java
Stelle
5.5k
Fork
1.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

private void start() {
L.i("开始预加载:" + mPosition);
Log.d(TAG, "start: >>>"+"开始预加载aaa");
Toast.makeText(MyApplication.getAppInstance(), "开始预加载", Toast.LENGTH_SHORT).show();
HttpURLConnection connection = null;
try {
//获取HttpProxyCacheServer的代理地址
String proxyUrl = mCacheServer.getProxyUrl(mRawUrl);
Log.d(TAG, "start: >>>"+"开始预加载proxyUrl");
Log.d(TAG, "start: >>>"+proxyUrl);
URL url = new URL(proxyUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setConnectTimeout(3000);
connection.setReadTimeout(3000);
InputStream in = new BufferedInputStream(connection.getInputStream());
Log.d(TAG, "start: >>>"+"进行预加载");
Toast.makeText(MyApplication.getAppInstance(), "预加载。。", Toast.LENGTH_SHORT).show();
int length;
int read = -1;
byte[] bytes = new byte[8 * 1024];
//读到bytes数组里面去
while ((length = in.read(bytes)) != -1) {
read += length;
//预加载完成或者取消预加载
if (mIsCanceled || read >= PreloadManager.PRELOAD_LENGTH) {
L.i("结束预加载:" + mPosition);
Log.d(TAG, "start: >>>"+"结束预加载");
Toast.makeText(MyApplication.getAppInstance(), "结束预加载", Toast.LENGTH_SHORT).show();
break;
}
}
if (read == -1) { //这种情况一般是预加载出错了,删掉缓存
L.i("预加载失败:" + mPosition);
Toast.makeText(MyApplication.getAppInstance(), "预加载失败", Toast.LENGTH_SHORT).show();
File cacheFile = mCacheServer.getCacheFile(mRawUrl);
if (cacheFile.exists()) {
cacheFile.delete();
}
}
} catch (Exception e) {
L.i("异常结束预加载:" + mPosition);
Log.d(TAG, "start: >>>"+"异常");
Toast.makeText(MyApplication.getAppInstance(), "异常结束预加载", Toast.LENGTH_SHORT).show();
} finally {
if (connection != null) {
connection.disconnect();
Log.d(TAG, "start: >>>"+"异常");
}
}
}
这个方法走不完

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.