长度显示减去进度条
length shows minus in progress bar
我正在从 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);
}
}
主要是服务器没有设置Content-Length
header参数。就像您从 Gdrive 下载时一样,它不会在下载过程中显示总文件大小。
简单的回答是内容长度未知。或者更具体地说,服务器没有在响应消息中设置 Content-Length header。
详细的解决方法是described here.
我正在从 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);
}
}
主要是服务器没有设置Content-Length
header参数。就像您从 Gdrive 下载时一样,它不会在下载过程中显示总文件大小。
简单的回答是内容长度未知。或者更具体地说,服务器没有在响应消息中设置 Content-Length header。
详细的解决方法是described here.