aboutsummaryrefslogtreecommitdiff
path: root/src/github
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-03-04 17:49:54 -0800
committerScott Jackson <daneren2005@gmail.com>2015-03-04 17:49:54 -0800
commit63517523d48deeefe35864d8ac71c8d12f40e38a (patch)
treef9417c5652d0dd9191e1cbab304f48d9ed49d789 /src/github
parent4391e7f6e53226e8434050e9306e655684c761b9 (diff)
parent7eafe80b36030cc9f3df5d14d01190c962f29ec7 (diff)
downloaddsub-63517523d48deeefe35864d8ac71c8d12f40e38a.tar.gz
dsub-63517523d48deeefe35864d8ac71c8d12f40e38a.tar.bz2
dsub-63517523d48deeefe35864d8ac71c8d12f40e38a.zip
Merge branch 'CastProxy'
Diffstat (limited to 'src/github')
-rw-r--r--src/github/daneren2005/dsub/service/CachedMusicService.java4
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java38
-rw-r--r--src/github/daneren2005/dsub/service/DLNAController.java29
-rw-r--r--src/github/daneren2005/dsub/service/RESTMusicService.java5
-rw-r--r--src/github/daneren2005/dsub/service/RemoteController.java10
-rw-r--r--src/github/daneren2005/dsub/util/Constants.java1
-rw-r--r--src/github/daneren2005/dsub/util/Util.java5
-rw-r--r--src/github/daneren2005/dsub/view/HeaderGridView.java8
8 files changed, 93 insertions, 7 deletions
diff --git a/src/github/daneren2005/dsub/service/CachedMusicService.java b/src/github/daneren2005/dsub/service/CachedMusicService.java
index 09347d1d..dec3c665 100644
--- a/src/github/daneren2005/dsub/service/CachedMusicService.java
+++ b/src/github/daneren2005/dsub/service/CachedMusicService.java
@@ -1325,4 +1325,8 @@ public class CachedMusicService implements MusicService {
musicFolderId = newMusicFolderId;
}
}
+
+ public RESTMusicService getMusicService() {
+ return musicService;
+ }
}
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index f5def994..a729ed4e 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -45,6 +45,8 @@ import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.compat.CastCompat;
import github.daneren2005.serverproxy.FileProxy;
+import github.daneren2005.serverproxy.ServerProxy;
+import github.daneren2005.serverproxy.WebProxy;
/**
* Created by owner on 2/9/14.
@@ -61,7 +63,7 @@ public class ChromeCastController extends RemoteController {
private boolean ignoreNextPaused = false;
private String sessionId;
- private FileProxy proxy;
+ private ServerProxy proxy;
private String rootLocation;
private RemoteMediaPlayer mediaPlayer;
private double gain = 0.5;
@@ -270,9 +272,26 @@ public class ChromeCastController extends RemoteController {
proxy.start();
}
- url = proxy.getPublicAddress(song.getId());
+ // Offline song
+ if(song.getId().indexOf(rootLocation) != -1) {
+ url = proxy.getPublicAddress(song.getId());
+ } else {
+ // Playing online song in offline mode
+ url = proxy.getPublicAddress(currentPlaying.getCompleteFile().getPath());
+ }
} else {
- if(proxy != null) {
+ // Check if we want a proxy going still
+ if(Util.isCastProxy(downloadService)) {
+ if(proxy instanceof FileProxy) {
+ proxy.stop();
+ proxy = null;
+ }
+
+ if(proxy == null) {
+ proxy = createWebProxy();
+ proxy.start();
+ }
+ } else if(proxy != null) {
proxy.stop();
proxy = null;
}
@@ -282,6 +301,11 @@ public class ChromeCastController extends RemoteController {
} else {
url = musicService.getMusicUrl(downloadService, song, currentPlaying.getBitRate());
}
+
+ // If proxy is going, it is a WebProxy
+ if(proxy != null) {
+ url = proxy.getPublicAddress(url);
+ }
}
// Setup song/video information
@@ -296,8 +320,14 @@ public class ChromeCastController extends RemoteController {
meta.putString(MediaMetadata.KEY_ALBUM_TITLE, song.getAlbum());
String coverArt = "";
- if(proxy == null) {
+ if(proxy == null || proxy instanceof WebProxy) {
coverArt = musicService.getCoverArtUrl(downloadService, song);
+
+ // If proxy is going, it is a web proxy
+ if(proxy != null) {
+ coverArt = proxy.getPublicAddress(coverArt);
+ }
+
meta.addImage(new WebImage(Uri.parse(coverArt)));
} else {
File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song);
diff --git a/src/github/daneren2005/dsub/service/DLNAController.java b/src/github/daneren2005/dsub/service/DLNAController.java
index d4777428..5daf0910 100644
--- a/src/github/daneren2005/dsub/service/DLNAController.java
+++ b/src/github/daneren2005/dsub/service/DLNAController.java
@@ -67,6 +67,8 @@ import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.serverproxy.FileProxy;
+import github.daneren2005.serverproxy.ServerProxy;
+import github.daneren2005.serverproxy.WebProxy;
public class DLNAController extends RemoteController {
private static final String TAG = DLNAController.class.getSimpleName();
@@ -78,7 +80,7 @@ public class DLNAController extends RemoteController {
SubscriptionCallback callback;
boolean supportsSeek = false;
- private FileProxy proxy;
+ private ServerProxy proxy;
String rootLocation = "";
boolean error = false;
@@ -401,7 +403,18 @@ public class DLNAController extends RemoteController {
url = proxy.getPublicAddress(currentPlaying.getCompleteFile().getPath());
}
} else {
- if(proxy != null) {
+ // Check if we want a proxy going still
+ if(Util.isCastProxy(downloadService)) {
+ if(proxy instanceof FileProxy) {
+ proxy.stop();
+ proxy = null;
+ }
+
+ if(proxy == null) {
+ proxy = createWebProxy();
+ proxy.start();
+ }
+ } else if(proxy != null) {
proxy.stop();
proxy = null;
}
@@ -411,6 +424,11 @@ public class DLNAController extends RemoteController {
} else {
url = musicService.getMusicUrl(downloadService, song, currentPlaying.getBitRate());
}
+
+ // If proxy is going, it is a WebProxy
+ if(proxy != null) {
+ url = proxy.getPublicAddress(url);
+ }
}
// Create metadata for entry
@@ -447,8 +465,13 @@ public class DLNAController extends RemoteController {
if(song.getCoverArt() != null) {
String coverArt = null;
- if(proxy == null) {
+ if(proxy == null || proxy instanceof WebProxy) {
coverArt = musicService.getCoverArtUrl(downloadService, song);
+
+ // If proxy is going, it is a web proxy
+ if(proxy != null) {
+ coverArt = proxy.getPublicAddress(coverArt);
+ }
} else {
File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song);
if(coverArtFile != null && coverArtFile.exists()) {
diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java
index 69c0b236..40a2f849 100644
--- a/src/github/daneren2005/dsub/service/RESTMusicService.java
+++ b/src/github/daneren2005/dsub/service/RESTMusicService.java
@@ -39,6 +39,7 @@ import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
@@ -1877,4 +1878,8 @@ public class RESTMusicService implements MusicService {
return Util.getRestUrl(context, method, instance, allowAltAddress);
}
}
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
}
diff --git a/src/github/daneren2005/dsub/service/RemoteController.java b/src/github/daneren2005/dsub/service/RemoteController.java
index 02deaf85..4483598c 100644
--- a/src/github/daneren2005/dsub/service/RemoteController.java
+++ b/src/github/daneren2005/dsub/service/RemoteController.java
@@ -32,6 +32,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.RemoteStatus;
+import github.daneren2005.serverproxy.WebProxy;
public abstract class RemoteController {
private static final String TAG = RemoteController.class.getSimpleName();
@@ -95,4 +96,13 @@ public abstract class RemoteController {
queue.clear();
}
}
+
+ protected WebProxy createWebProxy() {
+ MusicService musicService = MusicServiceFactory.getMusicService(downloadService);
+ if(musicService instanceof CachedMusicService) {
+ return new WebProxy(downloadService, ((CachedMusicService)musicService).getMusicService().getHttpClient());
+ } else {
+ return new WebProxy(downloadService);
+ }
+ }
}
diff --git a/src/github/daneren2005/dsub/util/Constants.java b/src/github/daneren2005/dsub/util/Constants.java
index d97fe8d0..b0bbfe31 100644
--- a/src/github/daneren2005/dsub/util/Constants.java
+++ b/src/github/daneren2005/dsub/util/Constants.java
@@ -152,6 +152,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_REPLAY_GAIN_UNTAGGED = "replayGainUntagged2";
public static final String PREFERENCES_KEY_REPLAY_GAIN_TYPE= "replayGainType";
public static final String PREFERENCES_KEY_ALBUMS_PER_FOLDER = "albumsPerFolder";
+ public static final String PREFERENCES_KEY_CAST_PROXY = "castProxy";
public static final String OFFLINE_SCROBBLE_COUNT = "scrobbleCount";
public static final String OFFLINE_SCROBBLE_ID = "scrobbleID";
diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java
index 01588bf2..1eaf71f8 100644
--- a/src/github/daneren2005/dsub/util/Util.java
+++ b/src/github/daneren2005/dsub/util/Util.java
@@ -560,6 +560,11 @@ public final class Util {
return Math.max(0, Constants.FREE_TRIAL_DAYS - daysSinceInstall);
}
+ public static boolean isCastProxy(Context context) {
+ SharedPreferences prefs = getPreferences(context);
+ return prefs.getBoolean(Constants.PREFERENCES_KEY_CAST_PROXY, false);
+ }
+
/**
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
* <p/>
diff --git a/src/github/daneren2005/dsub/view/HeaderGridView.java b/src/github/daneren2005/dsub/view/HeaderGridView.java
index 8e1eddac..c8e51764 100644
--- a/src/github/daneren2005/dsub/view/HeaderGridView.java
+++ b/src/github/daneren2005/dsub/view/HeaderGridView.java
@@ -300,6 +300,14 @@ public class HeaderGridView extends GridView {
mRowHeight = -1;
}
+ public int getHeaderHeight(int row) {
+ if (row >= 0) {
+ return mHeaderViewInfos.get(row).view.getMeasuredHeight();
+ }
+
+ return 0;
+ }
+
public int getRowHeight() {
if (mRowHeight > 0) {
return mRowHeight;