From e239b215a067e2d1de7201f0b9182cdcf59d818b Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Sun, 22 Feb 2015 11:08:49 -0800 Subject: #320 Start of option to pass traffic while casting through device proxy --- .../daneren2005/dsub/service/DLNAController.java | 29 +++++++++++++++++++--- src/github/daneren2005/dsub/util/Constants.java | 1 + src/github/daneren2005/dsub/util/Util.java | 5 ++++ 3 files changed, 32 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/DLNAController.java b/src/github/daneren2005/dsub/service/DLNAController.java index cdff990b..a2894a23 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(); @@ -77,7 +79,7 @@ public class DLNAController extends RemoteController { SubscriptionCallback callback; boolean supportsSeek = false; - private FileProxy proxy; + private ServerProxy proxy; String rootLocation = ""; boolean error = false; @@ -388,7 +390,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 = new WebProxy(downloadService); + proxy.start(); + } + } else if(proxy != null) { proxy.stop(); proxy = null; } @@ -398,6 +411,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 @@ -434,8 +452,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/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 InputStream as a byte[]. *

-- cgit v1.2.3 From a5d0e6ed8f6e2b9cfec96c45087fe1b7b5bd2a2f Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 25 Feb 2015 18:50:55 -0800 Subject: Add getHeaderHeight method (merged from source) --- src/github/daneren2005/dsub/view/HeaderGridView.java | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/github/daneren2005/dsub/view/HeaderGridView.java b/src/github/daneren2005/dsub/view/HeaderGridView.java index 350e90ee..51d08ebf 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; -- cgit v1.2.3 From dae987d86671333ba00b70c236484e5c67d00a8d Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 26 Feb 2015 12:07:45 -0800 Subject: Use proxy for ChromeCast as well --- .../dsub/service/ChromeCastController.java | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java index f5def994..21ee6e13 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 = new WebProxy(downloadService); + 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); -- cgit v1.2.3 From a0602c7759572c4af8947688132f8f7e97fb1563 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 3 Mar 2015 18:17:04 -0800 Subject: #320 Update with WebProxy using our custom httpClient (so we can bypass self-signed certs) --- ServerProxy | 2 +- src/github/daneren2005/dsub/service/ChromeCastController.java | 2 +- src/github/daneren2005/dsub/service/DLNAController.java | 2 +- src/github/daneren2005/dsub/service/RESTMusicService.java | 5 +++++ src/github/daneren2005/dsub/service/RemoteController.java | 10 ++++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/ServerProxy b/ServerProxy index 027c1077..a0c6e29d 160000 --- a/ServerProxy +++ b/ServerProxy @@ -1 +1 @@ -Subproject commit 027c10776b34e56a91850020d220a74499f16381 +Subproject commit a0c6e29d0dc455dc560327c44743eb549c72d753 diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java index 21ee6e13..a729ed4e 100644 --- a/src/github/daneren2005/dsub/service/ChromeCastController.java +++ b/src/github/daneren2005/dsub/service/ChromeCastController.java @@ -288,7 +288,7 @@ public class ChromeCastController extends RemoteController { } if(proxy == null) { - proxy = new WebProxy(downloadService); + proxy = createWebProxy(); proxy.start(); } } else if(proxy != null) { diff --git a/src/github/daneren2005/dsub/service/DLNAController.java b/src/github/daneren2005/dsub/service/DLNAController.java index a2894a23..701034de 100644 --- a/src/github/daneren2005/dsub/service/DLNAController.java +++ b/src/github/daneren2005/dsub/service/DLNAController.java @@ -398,7 +398,7 @@ public class DLNAController extends RemoteController { } if(proxy == null) { - proxy = new WebProxy(downloadService); + proxy = createWebProxy(); proxy.start(); } } else if(proxy != null) { diff --git a/src/github/daneren2005/dsub/service/RESTMusicService.java b/src/github/daneren2005/dsub/service/RESTMusicService.java index 341b1158..307afc9a 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; @@ -1878,4 +1879,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..47730e8c 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 RESTMusicService) { + return new WebProxy(downloadService, ((RESTMusicService)musicService).getHttpClient()); + } else { + return new WebProxy(downloadService); + } + } } -- cgit v1.2.3 From 7eafe80b36030cc9f3df5d14d01190c962f29ec7 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 3 Mar 2015 18:26:00 -0800 Subject: #320 Fix not using custom httpClient because factory returns Cached, not REST music service --- src/github/daneren2005/dsub/service/CachedMusicService.java | 4 ++++ src/github/daneren2005/dsub/service/RemoteController.java | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'src') 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/RemoteController.java b/src/github/daneren2005/dsub/service/RemoteController.java index 47730e8c..4483598c 100644 --- a/src/github/daneren2005/dsub/service/RemoteController.java +++ b/src/github/daneren2005/dsub/service/RemoteController.java @@ -99,8 +99,8 @@ public abstract class RemoteController { protected WebProxy createWebProxy() { MusicService musicService = MusicServiceFactory.getMusicService(downloadService); - if(musicService instanceof RESTMusicService) { - return new WebProxy(downloadService, ((RESTMusicService)musicService).getHttpClient()); + if(musicService instanceof CachedMusicService) { + return new WebProxy(downloadService, ((CachedMusicService)musicService).getMusicService().getHttpClient()); } else { return new WebProxy(downloadService); } -- cgit v1.2.3