-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
预加载进不去啊 #296
Comments
我也遇到了相同的问题, 就是在下载过程中,有时候突然就不走了,不知道为啥...你遇到过吗 |
而且感觉他的缓存速度好慢啊 |
走不完,没有异常信息么,网络错误或者是io读取错误之类的 |
request需要添加range合适一点,前提是服务器本身支持range。connection.setRequestProperty("Range", String.format("bytes=%d-%d", 0, PreloadManager.PRELOAD_LENGTH)); |
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: >>>"+"异常");
}
}
}
这个方法走不完
The text was updated successfully, but these errors were encountered: