aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaneren2005 <daneren2005@gmail.com>2013-10-01 14:01:54 -0700
committerdaneren2005 <daneren2005@gmail.com>2013-10-01 14:01:54 -0700
commita91a034fc78b07481fcb55ebafc9256a18660fd4 (patch)
treea6ac19a893fc8a635cb07f23c4d8781f0d139123
parent64b9fdf2ad2cc74bdc807165285a68149d82811f (diff)
downloaddsub-a91a034fc78b07481fcb55ebafc9256a18660fd4.tar.gz
dsub-a91a034fc78b07481fcb55ebafc9256a18660fd4.tar.bz2
dsub-a91a034fc78b07481fcb55ebafc9256a18660fd4.zip
Stream Proxy works off of partial or complete
Previously only worked if it was finding the partial file
-rw-r--r--src/github/daneren2005/dsub/service/StreamProxy.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/service/StreamProxy.java b/src/github/daneren2005/dsub/service/StreamProxy.java
index 0b269de6..287cb475 100644
--- a/src/github/daneren2005/dsub/service/StreamProxy.java
+++ b/src/github/daneren2005/dsub/service/StreamProxy.java
@@ -90,10 +90,10 @@ public class StreamProxy implements Runnable {
}
private class StreamToMediaPlayerTask implements Runnable {
-
- String localPath;
+ DownloadFile downloadFile;
+ File file;
Socket client;
- int cbSkip;
+ int cbSkip = 0;
public StreamToMediaPlayerTask(Socket client) {
this.client = client;
@@ -149,6 +149,7 @@ public class StreamProxy implements Runnable {
// Read HTTP headers
Log.i(TAG, "Processing request");
+ String localPath;
try {
localPath = URLDecoder.decode(request.getRequestLine().getUri(), Constants.UTF_8);
} catch (UnsupportedEncodingException e) {
@@ -157,19 +158,22 @@ public class StreamProxy implements Runnable {
}
Log.i(TAG, "Processing request for file " + localPath);
- File file = new File(localPath);
- if (!file.exists()) {
+ downloadFile = downloadService.getCurrentPlaying();
+ File partialFile = new File(localPath);
+ if (!file.equals(downloadFile.getPartialFile()) {
Log.e(TAG, "File " + localPath + " does not exist");
return false;
}
+ // Use either partial or complete if downloading finished while StreamProxy was idle
+ file = downloadFile.isCompleteFileAvailable() ? downloadFile.getCompleteFile() : downloadFile.getPartialFile();
+
return true;
}
@Override
public void run() {
Log.i(TAG, "Streaming song in background");
- DownloadFile downloadFile = downloadService.getCurrentPlaying();
MusicDirectory.Entry song = downloadFile.getSong();
// Create HTTP header
@@ -204,7 +208,6 @@ public class StreamProxy implements Runnable {
while (isRunning && !client.isClosed()) {
// See if there's more to send
- File file = new File(localPath);
int cbSentThisBatch = 0;
if (file.exists()) {
FileInputStream input = new FileInputStream(file);