mirror of
https://github.com/zhigang1992/AndroidVideoCache.git
synced 2026-04-26 22:35:13 +08:00
fix dividing by zero while loading empty file (#26)
This commit is contained in:
@@ -91,7 +91,7 @@ public class HttpProxyCacheServer {
|
||||
|
||||
private void makeSureServerWorks() {
|
||||
int maxPingAttempts = 3;
|
||||
int delay = 200;
|
||||
int delay = 300;
|
||||
int pingAttempts = 0;
|
||||
while (pingAttempts < maxPingAttempts) {
|
||||
try {
|
||||
@@ -107,7 +107,7 @@ public class HttpProxyCacheServer {
|
||||
pingAttempts++;
|
||||
delay *= 2;
|
||||
}
|
||||
Log.e(LOG_TAG, "Shutdown server… Error pinging server [attempt: " + pingAttempts + ", timeout: " + delay + "]. " +
|
||||
Log.e(LOG_TAG, "Shutdown server… Error pinging server [attempts: " + pingAttempts + ", max timeout: " + delay / 2 + "]. " +
|
||||
"If you see this message, please, email me danikula@gmail.com");
|
||||
shutdown();
|
||||
}
|
||||
|
||||
@@ -100,10 +100,11 @@ class ProxyCache {
|
||||
}
|
||||
}
|
||||
|
||||
protected void onCacheAvailable(long cacheAvailable, long sourceAvailable) {
|
||||
int percents = (int) (cacheAvailable * 100 / sourceAvailable);
|
||||
protected void onCacheAvailable(long cacheAvailable, long sourceLength) {
|
||||
boolean zeroLengthSource = sourceLength == 0;
|
||||
int percents = zeroLengthSource ? 100 : (int) (cacheAvailable * 100 / sourceLength);
|
||||
boolean percentsChanged = percents != percentsAvailable;
|
||||
boolean sourceLengthKnown = sourceAvailable >= 0;
|
||||
boolean sourceLengthKnown = sourceLength >= 0;
|
||||
if (sourceLengthKnown && percentsChanged) {
|
||||
onCachePercentsAvailableChanged(percents);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user