aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-04-24 19:37:48 -0700
committerScott Jackson <daneren2005@gmail.com>2014-04-24 19:37:48 -0700
commit6fcb9e6dfd4df89062b62365659592948c247a67 (patch)
tree2f51e6f25ea119f48c97e98ae7e5c1c2672de388 /src
parentb2643032f7a776c36c9d0ffae79acbc304b7feb9 (diff)
downloaddsub-6fcb9e6dfd4df89062b62365659592948c247a67.tar.gz
dsub-6fcb9e6dfd4df89062b62365659592948c247a67.tar.bz2
dsub-6fcb9e6dfd4df89062b62365659592948c247a67.zip
#27 Control volume from outside app while in remote mode
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java8
-rw-r--r--src/github/daneren2005/dsub/util/MediaRouteManager.java8
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java19
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java3
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java12
5 files changed, 46 insertions, 4 deletions
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index 8fecc893..b695fd72 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -70,6 +70,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.PowerManager;
import android.support.v7.media.MediaRouteSelector;
+import android.support.v7.media.MediaRouter;
import android.util.Log;
import android.support.v4.util.LruCache;
import java.net.URLEncoder;
@@ -1227,6 +1228,13 @@ public class DownloadService extends Service {
}
}
+ public void registerRoute(MediaRouter router) {
+ mRemoteControl.registerRoute(router);
+ }
+ public void unregisterRoute(MediaRouter router) {
+ mRemoteControl.unregisterRoute(router);
+ }
+
public void setRemoteVolume(boolean up) {
remoteController.setVolume(up);
}
diff --git a/src/github/daneren2005/dsub/util/MediaRouteManager.java b/src/github/daneren2005/dsub/util/MediaRouteManager.java
index b227916f..cad8afe3 100644
--- a/src/github/daneren2005/dsub/util/MediaRouteManager.java
+++ b/src/github/daneren2005/dsub/util/MediaRouteManager.java
@@ -85,9 +85,17 @@ public class MediaRouteManager extends MediaRouter.Callback {
downloadService.setRemoteEnabled(RemoteControlState.CHROMECAST, controller);
}
}
+
+ if(downloadService.isRemoteEnabled()) {
+ downloadService.registerRoute(router);
+ }
}
@Override
public void onRouteUnselected(MediaRouter router, RouteInfo info) {
+ if(downloadService.isRemoteEnabled()) {
+ downloadService.unregisterRoute(router);
+ }
+
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
}
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
index c3f3f70c..320092e9 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
@@ -3,6 +3,7 @@ package github.daneren2005.dsub.util.compat;
import github.daneren2005.dsub.domain.MusicDirectory.Entry;
import android.content.ComponentName;
import android.content.Context;
+import android.support.v7.media.MediaRouter;
import android.util.Log;
public class RemoteControlClientBase extends RemoteControlClientHelper {
@@ -11,22 +12,32 @@ public class RemoteControlClientBase extends RemoteControlClientHelper {
@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void unregister(Context context) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void setPlaybackState(int state) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
}
@Override
public void updateMetadata(Context context, Entry currentSong) {
- Log.w(TAG, "RemoteControlClient requires Android API level 14 or higher.");
+
+ }
+
+ @Override
+ public void registerRoute(MediaRouter router) {
+
+ }
+
+ @Override
+ public void unregisterRoute(MediaRouter router) {
+
}
}
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
index 9826851d..93075a28 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientHelper.java
@@ -3,6 +3,7 @@ package github.daneren2005.dsub.util.compat;
import github.daneren2005.dsub.domain.MusicDirectory;
import android.content.ComponentName;
import android.content.Context;
+import android.support.v7.media.MediaRouter;
import android.os.Build;
public abstract class RemoteControlClientHelper {
@@ -25,5 +26,7 @@ public abstract class RemoteControlClientHelper {
public abstract void unregister(final Context context);
public abstract void setPlaybackState(final int state);
public abstract void updateMetadata(final Context context, final MusicDirectory.Entry currentSong);
+ public abstract void registerRoute(MediaRouter router);
+ public abstract void unregisterRoute(MediaRouter router);
}
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
index 56378a25..50283da6 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
@@ -11,6 +11,7 @@ import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.RemoteControlClient;
+import android.support.v7.media.MediaRouter;
import github.daneren2005.dsub.activity.SubsonicActivity;
@@ -68,6 +69,17 @@ public class RemoteControlClientICS extends RemoteControlClientHelper {
imageLoader.loadImage(context, mRemoteControl, currentSong);
}
}
+
+ @Override
+ public void registerRoute(MediaRouter router) {
+ router.addRemoteControlClient(mRemoteControl);
+ }
+
+ @Override
+ public void unregisterRoute(MediaRouter router) {
+ router.removeRemoteControlClient(mRemoteControl);
+ }
+
protected void updateMetadata(final MusicDirectory.Entry currentSong, final RemoteControlClient.MetadataEditor editor) {
editor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, (currentSong == null) ? null : currentSong.getArtist())
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, (currentSong == null) ? null : currentSong.getAlbum())