diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-12-28 21:24:42 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-12-28 21:24:42 -0800 |
commit | c4a4edf10496be81005444e2cb6f22a151491840 (patch) | |
tree | 24440e3d7eea65b24c7f4d5b2062bc9acea811f4 | |
parent | fbe74414d7d5d1d5ab2bb8db714464483727cee5 (diff) | |
download | dsub-c4a4edf10496be81005444e2cb6f22a151491840.tar.gz dsub-c4a4edf10496be81005444e2cb6f22a151491840.tar.bz2 dsub-c4a4edf10496be81005444e2cb6f22a151491840.zip |
Closes #76 Fix when file is completely downloaded and app is resumed trying to redownload file
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java index bfb238d0..6f253d84 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java @@ -258,24 +258,26 @@ public class DownloadFile { MusicService musicService = MusicServiceFactory.getMusicService(context); // Attempt partial HTTP GET, appending to the file if it exists. - HttpResponse response = musicService.getDownloadInputStream(context, song, partialFile.length(), bitRate, DownloadTask.this); - in = response.getEntity().getContent(); - boolean partial = response.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT; - if (partial) { - Log.i(TAG, "Executed partial HTTP GET, skipping " + partialFile.length() + " bytes"); - } + if((bitRate * song.getDuration() * 1000 / 8) > partialFile.length()) { + HttpResponse response = musicService.getDownloadInputStream(context, song, partialFile.length(), bitRate, DownloadTask.this); + in = response.getEntity().getContent(); + boolean partial = response.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT; + if (partial) { + Log.i(TAG, "Executed partial HTTP GET, skipping " + partialFile.length() + " bytes"); + } - out = new FileOutputStream(partialFile, partial); - long n = copy(in, out); - Log.i(TAG, "Downloaded " + n + " bytes to " + partialFile); - out.flush(); - out.close(); + out = new FileOutputStream(partialFile, partial); + long n = copy(in, out); + Log.i(TAG, "Downloaded " + n + " bytes to " + partialFile); + out.flush(); + out.close(); - if (isCancelled()) { - throw new Exception("Download of '" + song + "' was cancelled"); - } + if (isCancelled()) { + throw new Exception("Download of '" + song + "' was cancelled"); + } - downloadAndSaveCoverArt(musicService); + downloadAndSaveCoverArt(musicService); + } if(isPlaying) { completeWhenDone = true; |