MultiThreadDownloader
MultiThreadDownloader copied to clipboard
如何获取下载速度
Please write english.
@salehmosleh how to get the speed?
here is an example , update CallBack Request class , method onProgress in your service:
private long mLastTime=0;
private long _last_finished = 0;
private DecimalFormat DF = new DecimalFormat("0.00")
@Override
public void onProgress(long finished, long total, int progress) {
if (mLastTime == 0) {
fifn.Status = FileInfo.STATUS_DOWNLOADING;
mLastTime = System.currentTimeMillis();
fifn.filesize = total;
updateDB();
}
fifn.progress = progress;
fifn.downloadPerSize = getDownloadPerSize(finished, total);
fifn.Status = FileInfo.STATUS_DOWNLOADING;
long currentTime = System.currentTimeMillis();
if (currentTime - mLastTime > 800) {
double downspeedn = (((double)(finished-_last_finished))/1024d)/0.80d;
String downspeed = DF.format(downspeedn);
notify.setContentText("speed is "+downspeed+"KB/s ...");
notify.setProgress(100, progress, false);
mLastTime = currentTime;
_last_finished = finished;
updateNotification(FileInfo.STATUS_DOWNLOADING);
sendBroadCast();
}
}
public String getDownloadPerSize(long finished, long total) {
return (DF.format((float) finished / (1024 * 1024)) + "M/" +
DF.format((float) total / (1024 * 1024)) + "M");
}
@salehmosleh thanks.