aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-02-06 16:07:35 -0800
committerScott Jackson <daneren2005@gmail.com>2014-02-06 16:07:35 -0800
commit04dea2ee1d7fddf143f6690ab95e71754628e346 (patch)
treeb59f8eb51ce7c201c42768ca739f98879dd680f1
parentf048ecd83239d40a17315524a2cbdd0e35678568 (diff)
downloaddsub-04dea2ee1d7fddf143f6690ab95e71754628e346.tar.gz
dsub-04dea2ee1d7fddf143f6690ab95e71754628e346.tar.bz2
dsub-04dea2ee1d7fddf143f6690ab95e71754628e346.zip
Added methods to get more info from DownloadFile
-rw-r--r--src/github/daneren2005/dsub/service/DownloadFile.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadFile.java b/src/github/daneren2005/dsub/service/DownloadFile.java
index d7a05da7..cfadced5 100644
--- a/src/github/daneren2005/dsub/service/DownloadFile.java
+++ b/src/github/daneren2005/dsub/service/DownloadFile.java
@@ -63,6 +63,7 @@ public class DownloadFile {
private boolean saveWhenDone = false;
private boolean completeWhenDone = false;
private Integer contentLength = null;
+ private int currentSpeed = 0;
public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) {
this.context = context;
@@ -110,6 +111,40 @@ public class DownloadFile {
return contentLength;
}
+ public int getCurrentSize() {
+ if(partialFile.exists()) {
+ return partialFile.length();
+ } else {
+ File file = getCompleteFile();
+ if(file.exists()) {
+ return file.length();
+ } else {
+ return 0;
+ }
+ }
+ }
+
+ public int getEstimatedSize() {
+ if(contentLength != null) {
+ return contentLength;
+ }
+
+ File file = getCompleteFile();
+ if(file.exists()) {
+ return file.length();
+ } else if(song.getDuration() == null) {
+ return 0;
+ } else {
+ int br = getBitrate();
+ int duration = song.getDuration();
+ return br * duration;
+ }
+ }
+
+ public int getBytesPerSecond() {
+ return currentSpeed;
+ }
+
public synchronized void download() {
preDownload();
downloadTask.start();
@@ -430,15 +465,19 @@ public class DownloadFile {
long count = 0;
int n;
long lastLog = System.currentTimeMillis();
+ long lastCount = 0;
while (!isCancelled() && (n = in.read(buffer)) != -1) {
out.write(buffer, 0, n);
count += n;
+ lastCount += n;
long now = System.currentTimeMillis();
if (now - lastLog > 3000L) { // Only every so often.
Log.i(TAG, "Downloaded " + Util.formatBytes(count) + " of " + song);
+ currentSpeed = lastCount / ((now - lastLog) / 1000L);
lastLog = now;
+ lastCount = 0;
}
}
return count;