From c4a4edf10496be81005444e2cb6f22a151491840 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 28 Dec 2012 21:24:42 -0800 Subject: Closes #76 Fix when file is completely downloaded and app is resumed trying to redownload file --- .../daneren2005/dsub/service/DownloadFile.java | 32 ++++++++++++---------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'subsonic-android/src/github/daneren2005') 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; -- cgit v1.2.3