aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-06-17 06:42:29 -0700
committerScott Jackson <daneren2005@gmail.com>2013-06-17 06:42:29 -0700
commitba3227ca9dc8fdfdc30883728e49d5804c33c11c (patch)
tree8be45a31a31b09a842c397971b22d721aaca83e7
parent1f83676ac07df3a0babd9e9571cb8bfaf09480a7 (diff)
downloaddsub-ba3227ca9dc8fdfdc30883728e49d5804c33c11c.tar.gz
dsub-ba3227ca9dc8fdfdc30883728e49d5804c33c11c.tar.bz2
dsub-ba3227ca9dc8fdfdc30883728e49d5804c33c11c.zip
Specify content-length on un transcoded songs
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadFile.java14
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/StreamProxy.java12
2 files changed, 24 insertions, 2 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/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";