aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java14
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java8
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java12
3 files changed, 31 insertions, 3 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
index 3fa38bdf..5ab7ad70 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java
@@ -34,6 +34,7 @@ import github.daneren2005.dsub.util.CancellableTask;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.CacheCleaner;
+import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
@@ -59,6 +60,7 @@ public class DownloadFile {
private boolean isPlaying = false;
private boolean saveWhenDone = false;
private boolean completeWhenDone = false;
+ private Integer contentLength = null;
public DownloadFile(Context context, MusicDirectory.Entry song, boolean save) {
this.context = context;
@@ -89,6 +91,10 @@ public class DownloadFile {
}
return song.getBitRate() == null ? 160 : song.getBitRate();
}
+
+ public Integer getContentLength() {
+ return contentLength;
+ }
public synchronized void download() {
FileUtil.createDirectoryForParent(saveFile);
@@ -270,6 +276,14 @@ public class DownloadFile {
if(compare) {
// Attempt partial HTTP GET, appending to the file if it exists.
HttpResponse response = musicService.getDownloadInputStream(context, song, partialFile.length(), bitRate, DownloadTask.this);
+ Header contentLengthHeader = response.getFirstHeader("Content-Length");
+ if(contentLengthHeader != null) {
+ String contentLengthString = contentLengthHeader.getValue();
+ if(contentLengthString != null) {
+ Log.i(TAG, "Content Length: " + contentLengthString);
+ contentLength = Integer.parseInt(contentLengthString);
+ }
+ }
in = response.getEntity().getContent();
boolean partial = response.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT;
if (partial) {
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index ba8ea1e4..4c02a831 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -282,16 +282,22 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
revision++;
} else {
+ int size = size();
+ int index = getCurrentPlayingIndex();
for (MusicDirectory.Entry song : songs) {
DownloadFile downloadFile = new DownloadFile(this, song, save);
downloadList.add(downloadFile);
}
+ if(!autoplay && (size - 1) == index) {
+ setNextPlaying();
+ }
revision++;
}
updateJukeboxPlaylist();
- if(shuffle)
+ if(shuffle) {
shuffle();
+ }
if (autoplay) {
play(0);
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java b/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java
index 13dbf479..24c1b201 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java
@@ -157,12 +157,20 @@ public class StreamProxy implements Runnable {
Log.i(TAG, "Streaming song in background");
DownloadFile downloadFile = downloadService.getCurrentPlaying();
MusicDirectory.Entry song = downloadFile.getSong();
- long fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
- Log.i(TAG, "Streaming fileSize: " + fileSize);
// Create HTTP header
String headers = "HTTP/1.0 200 OK\r\n";
headers += "Content-Type: " + "application/octet-stream" + "\r\n";
+
+ Integer contentLength = downloadFile.getContentLength();
+ long fileSize;
+ if(contentLength == null) {
+ fileSize = downloadFile.getBitRate() * ((song.getDuration() != null) ? song.getDuration() : 0) * 1000 / 8;
+ } else {
+ fileSize = contentLength;
+ headers += "Content-Length: " + fileSize + "\r\n";
+ }
+ Log.i(TAG, "Streaming fileSize: " + fileSize);
headers += "Connection: close\r\n";
headers += "\r\n";