diff --git a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy index 74d1375a..ffa8edae 100644 --- a/core/src/main/groovy/com/muwire/core/download/Downloader.groovy +++ b/core/src/main/groovy/com/muwire/core/download/Downloader.groovy @@ -164,14 +164,15 @@ public class Downloader { public int speed() { int currSpeed = 0 - if (getCurrentState() == DownloadState.DOWNLOADING) { - long dataRead = dataSinceLastRead.getAndSet(0) - long now = System.currentTimeMillis() - if (now > lastSpeedRead) - currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead)) - lastSpeedRead = now - } - + if (getCurrentState() != DownloadState.DOWNLOADING) + return currSpeed + long now = System.currentTimeMillis() + if (now < lastSpeedRead + 50) + return speedArr.average() + long dataRead = dataSinceLastRead.getAndSet(0) + currSpeed = (int) (dataRead * 1000.0d / (now - lastSpeedRead)) + lastSpeedRead = now + // this is not very accurate since each slot may hold more than a second if (speedArr.size() != downloadManager.muSettings.speedSmoothSeconds) { speedArr.clear()