danikula / danikula/AndroidVideoCache

预加载进不去啊

Offen
#296 4 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
5.5k
Forks
1.2k
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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: >>>"+"异常");
}
}
}
这个方法走不完

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.