我正在从URL下载视频,当我尝试获取进度显示负值时,在下面添加了我的代码,
byte[] buffer = new byte[1024];
int len1 = 0;
long total = 0;
while ((len1 = is.read(buffer)) != -1) {
if (cancelDialogStatus) {
break;
}
Log.e("System out", "doInBackground: progress:::" + len1);
total += len1;
// publishing the progress....
// After this onProgressUpdate will be called
int prg = (int) ((total * 100) / lenghtOfFile);
Log.d("System out", "doInBackground: progress:::" + prg);
if (prg > 100) {
publishProgress(""
+ 100);
fos.write(buffer, 0, len1);
break;
} else {
publishProgress(""
+ (int) ((total * 100) / lenghtOfFile));
fos.write(buffer, 0, len1);
}
}
答案 0 :(得分:1)
这基本上是由于服务器未设置Content-Length
头参数。就像从Gdrive下载时一样,下载过程中不会显示总文件大小。
简单的答案是内容长度未知。更具体地说,服务器未在响应消息中设置 Content-Length 标头。
详细的解决方案是described here.