danikula / danikula/AndroidVideoCache

预加载进不去啊

Đang mở
#296 4 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
5.5k
Fork
1.2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.