From 1796bf6a4c007b39e22696b6ae3c38aac62454e8 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Tue, 11 Oct 2016 17:02:33 -0700 Subject: Fixes #747: Add support for Internet Radio while casting --- .../SelectInternetRadioStationFragment.java | 2 +- .../dsub/service/ChromeCastController.java | 51 +---------------- .../daneren2005/dsub/service/DLNAController.java | 54 +----------------- .../dsub/service/JukeboxController.java | 2 +- .../daneren2005/dsub/service/RemoteController.java | 64 ++++++++++++++++++++++ 5 files changed, 71 insertions(+), 102 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java index c39e9f61..74c4b269 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/SelectInternetRadioStationFragment.java @@ -133,7 +133,7 @@ public class SelectInternetRadioStationFragment extends SelectRecyclerFragment(url, metadata); + return new Pair<>(url, metadata); } private void failedLoad() { diff --git a/app/src/main/java/github/daneren2005/dsub/service/JukeboxController.java b/app/src/main/java/github/daneren2005/dsub/service/JukeboxController.java index 82ef45e1..b9f40f32 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/JukeboxController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/JukeboxController.java @@ -48,7 +48,7 @@ public class JukeboxController extends RemoteController { private float gain = 0.5f; public JukeboxController(DownloadService downloadService, Handler handler) { - this.downloadService = downloadService; + super(downloadService); this.handler = handler; } diff --git a/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java b/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java index 2815bcc9..c6702e3e 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java +++ b/app/src/main/java/github/daneren2005/dsub/service/RemoteController.java @@ -19,20 +19,32 @@ package github.daneren2005.dsub.service; +import android.content.SharedPreferences; import android.util.Log; import java.util.Iterator; import java.util.concurrent.LinkedBlockingQueue; +import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.domain.RemoteStatus; import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.Util; +import github.daneren2005.serverproxy.FileProxy; +import github.daneren2005.serverproxy.ServerProxy; import github.daneren2005.serverproxy.WebProxy; public abstract class RemoteController { private static final String TAG = RemoteController.class.getSimpleName(); protected DownloadService downloadService; protected boolean nextSupported = false; + protected ServerProxy proxy; + protected String rootLocation = ""; + + public RemoteController(DownloadService downloadService) { + this.downloadService = downloadService; + SharedPreferences prefs = Util.getPreferences(downloadService); + rootLocation = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null); + } public abstract void create(boolean playing, int seconds); public abstract void start(); @@ -110,4 +122,56 @@ public abstract class RemoteController { return new WebProxy(downloadService); } } + + protected String getStreamUrl(MusicService musicService, DownloadFile downloadFile) throws Exception { + MusicDirectory.Entry song = downloadFile.getSong(); + + String url; + // In offline mode or playing offline song + if(downloadFile.isStream()) { + url = downloadFile.getStream(); + } else if(Util.isOffline(downloadService) || song.getId().indexOf(rootLocation) != -1) { + if(proxy == null) { + proxy = new FileProxy(downloadService); + proxy.start(); + } + + // Offline song + if(song.getId().indexOf(rootLocation) != -1) { + url = proxy.getPublicAddress(song.getId()); + } else { + // Playing online song in offline mode + url = proxy.getPublicAddress(downloadFile.getCompleteFile().getPath()); + } + } else { + // 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; + } + + if(song.isVideo()) { + url = musicService.getHlsUrl(song.getId(), downloadFile.getBitRate(), downloadService); + } else { + url = musicService.getMusicUrl(downloadService, song, downloadFile.getBitRate()); + } + + // If proxy is going, it is a WebProxy + if(proxy != null) { + url = proxy.getPublicAddress(url); + } + } + + return url; + } } -- cgit v1.2.3