aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-02-22 11:06:44 -0800
committerScott Jackson <daneren2005@gmail.com>2014-02-22 11:06:44 -0800
commitbe9219c4610a31f7a74ba9889a21cc1e0daff2a7 (patch)
tree97233c5969eda3e73d1a82ba0a5917e4c50bb253
parenta8d3785fc7685b097f305caedfc2f66aaaba6aee (diff)
downloaddsub-be9219c4610a31f7a74ba9889a21cc1e0daff2a7.tar.gz
dsub-be9219c4610a31f7a74ba9889a21cc1e0daff2a7.tar.bz2
dsub-be9219c4610a31f7a74ba9889a21cc1e0daff2a7.zip
#285 Add support for offline ChromeCast
m---------ServerProxy0
-rw-r--r--res/menu/nowplaying_offline.xml9
-rw-r--r--src/github/daneren2005/dsub/fragments/MainFragment.java4
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java59
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java9
-rw-r--r--src/github/daneren2005/dsub/util/MediaRouteManager.java19
6 files changed, 90 insertions, 10 deletions
diff --git a/ServerProxy b/ServerProxy
-Subproject 1fab7a8626616ea7f4df9aa3381a7c0bbf5529d
+Subproject 093db23954f2343d280317dc59d33cd039715bc
diff --git a/res/menu/nowplaying_offline.xml b/res/menu/nowplaying_offline.xml
index 41d1d5d1..7656bf34 100644
--- a/res/menu/nowplaying_offline.xml
+++ b/res/menu/nowplaying_offline.xml
@@ -7,12 +7,19 @@
android:icon="?attr/shuffle"
android:title="@string/download.menu_shuffle"
compat:showAsAction="always|withText"/>
+
+ <item
+ android:id="@+id/menu_mediaroute"
+ compat:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
+ compat:actionViewClass="android.support.v7.app.MediaRouteButton"
+ compat:showAsAction="always"
+ android:title="@string/menu.cast"/>
<item
android:id="@+id/menu_remove_all"
android:icon="?attr/remove"
android:title="@string/download.menu_remove_all"
- compat:showAsAction="always|withText"/>
+ compat:showAsAction="ifRoom|withText"/>
<item
android:id="@+id/menu_screen_on_off"
diff --git a/src/github/daneren2005/dsub/fragments/MainFragment.java b/src/github/daneren2005/dsub/fragments/MainFragment.java
index 1905e77a..20d4d9a5 100644
--- a/src/github/daneren2005/dsub/fragments/MainFragment.java
+++ b/src/github/daneren2005/dsub/fragments/MainFragment.java
@@ -208,6 +208,10 @@ public class MainFragment extends SubsonicFragment {
boolean isOffline = Util.isOffline(context);
Util.setOffline(context, !isOffline);
context.invalidate();
+ DownloadService service = getDownloadService();
+ if (service != null) {
+ service.setOnline(isOffline);
+ }
if(isOffline) {
int scrobblesCount = Util.offlineScrobblesCount(context);
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index dc360797..3cfde4c6 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -15,6 +15,7 @@
package github.daneren2005.dsub.service;
+import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
@@ -32,14 +33,17 @@ import com.google.android.gms.common.api.ResultCallback;
import com.google.android.gms.common.api.Status;
import com.google.android.gms.common.images.WebImage;
+import java.io.File;
import java.io.IOException;
import github.daneren2005.dsub.R;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.compat.CastCompat;
+import github.daneren2005.serverproxy.FileProxy;
/**
* Created by owner on 2/9/14.
@@ -58,12 +62,17 @@ public class ChromeCastController extends RemoteController {
private boolean error = false;
private boolean ignoreNextPaused = false;
+ private FileProxy proxy;
+ private String rootLocation;
private RemoteMediaPlayer mediaPlayer;
private double gain = 0.5;
public ChromeCastController(DownloadService downloadService, CastDevice castDevice) {
this.downloadService = downloadService;
this.castDevice = castDevice;
+
+ SharedPreferences prefs = Util.getPreferences(downloadService);
+ rootLocation = prefs.getString(Constants.PREFERENCES_KEY_CACHE_LOCATION, null);
}
@Override
@@ -154,6 +163,11 @@ public class ChromeCastController extends RemoteController {
apiClient.disconnect();
}
apiClient = null;
+
+ if(proxy != null) {
+ proxy.stop();
+ proxy = null;
+ }
}
@Override
@@ -209,9 +223,30 @@ public class ChromeCastController extends RemoteController {
try {
MusicService musicService = MusicServiceFactory.getMusicService(downloadService);
- String url = song.isVideo() ? musicService.getHlsUrl(song.getId(), currentPlaying.getBitRate(), downloadService) : musicService.getMusicUrl(downloadService, song, currentPlaying.getBitRate());
- // Use separate profile for Chromecast so users can do ogg on phone, mp3 for CC
- url = url.replace(Constants.REST_CLIENT_ID, Constants.CHROMECAST_CLIENT_ID);
+ String url;
+ // Offline, use file proxy
+ if(Util.isOffline(downloadService) || song.getId().indexOf(rootLocation) != -1) {
+ if(proxy == null) {
+ proxy = new FileProxy(downloadService);
+ proxy.start();
+ }
+
+ url = proxy.getPublicAddress(song.getId());
+ } else {
+ if(proxy != null) {
+ proxy.stop();
+ proxy = null;
+ }
+
+ if(song.isVideo()) {
+ url = musicService.getHlsUrl(song.getId(), currentPlaying.getBitRate(), downloadService);
+ } else {
+ url = musicService.getMusicUrl(downloadService, song, currentPlaying.getBitRate());
+ }
+
+ // Use separate profile for Chromecast so users can do ogg on phone, mp3 for CC
+ url = url.replace(Constants.REST_CLIENT_ID, Constants.CHROMECAST_CLIENT_ID);
+ }
// Setup song/video information
MediaMetadata meta = new MediaMetadata(song.isVideo() ? MediaMetadata.MEDIA_TYPE_MOVIE : MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
@@ -223,8 +258,18 @@ public class ChromeCastController extends RemoteController {
meta.putString(MediaMetadata.KEY_ARTIST, song.getArtist());
meta.putString(MediaMetadata.KEY_ALBUM_ARTIST, song.getArtist());
meta.putString(MediaMetadata.KEY_ALBUM_TITLE, song.getAlbum());
- String coverArt = musicService.getCoverArtUrl(downloadService, song);
- meta.addImage(new WebImage(Uri.parse(coverArt)));
+
+ String coverArt;
+ if(proxy == null) {
+ coverArt = musicService.getCoverArtUrl(downloadService, song);
+ meta.addImage(new WebImage(Uri.parse(coverArt)));
+ } else {
+ File coverArtFile = FileUtil.getAlbumArtFile(downloadService, song);
+ if(coverArtFile != null && coverArtFile.exists()) {
+ coverArt = coverArtFile.getPath();
+ meta.addImage(new WebImage(Uri.parse(proxy.getPublicAddress(coverArt))));
+ }
+ }
}
String contentType;
@@ -233,8 +278,10 @@ public class ChromeCastController extends RemoteController {
}
else if(song.getTranscodedContentType() != null) {
contentType = song.getTranscodedContentType();
- } else {
+ } else if(song.getContentType() != null) {
contentType = song.getContentType();
+ } else {
+ contentType = "audio/mpeg";
}
// Load it into a MediaInfo wrapper
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 5e02641a..b3a989ed 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -523,6 +523,15 @@ public class DownloadService extends Service {
updateJukeboxPlaylist();
}
+ public synchronized void setOnline(boolean online) {
+ if(online) {
+ mediaRouter.addOfflineProviders();
+ } else {
+ mediaRouter.removeOfflineProviders();
+ clearIncomplete();
+ }
+ }
+
public synchronized int size() {
return downloadList.size();
}
diff --git a/src/github/daneren2005/dsub/util/MediaRouteManager.java b/src/github/daneren2005/dsub/util/MediaRouteManager.java
index 4a124402..d41a5516 100644
--- a/src/github/daneren2005/dsub/util/MediaRouteManager.java
+++ b/src/github/daneren2005/dsub/util/MediaRouteManager.java
@@ -42,6 +42,7 @@ public class MediaRouteManager extends MediaRouter.Callback {
private MediaRouter router;
private MediaRouteSelector selector;
private List<MediaRouteProvider> providers = new ArrayList<MediaRouteProvider>();
+ private List<MediaRouteProvider> offlineProviders = new ArrayList<MediaRouteProvider>();
static {
try {
@@ -116,10 +117,22 @@ public class MediaRouteManager extends MediaRouter.Callback {
}
}
+ public void addOfflineProviders() {
+ JukeboxRouteProvider jukeboxProvider = new JukeboxRouteProvider(downloadService);
+ router.addProvider(jukeboxProvider);
+ providers.add(jukeboxProvider);
+ offlineProviders.add(jukeboxProvider);
+ }
+ public void removeOfflineProviders() {
+ for(MediaRouteProvider provider: offlineProviders) {
+ router.removeProvider(provider);
+ }
+ }
+
private void addProviders() {
- JukeboxRouteProvider routeProvider = new JukeboxRouteProvider(downloadService);
- router.addProvider(routeProvider);
- providers.add(routeProvider);
+ if(!Util.isOffline(downloadService)) {
+ addOfflineProviders();
+ }
}
private void buildSelector() {
MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder();