aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2014-04-24 20:59:57 -0700
committerScott Jackson <daneren2005@gmail.com>2014-04-24 20:59:57 -0700
commitcb9befec2a3c57c48b87b0f01cc086dd6bf83730 (patch)
treee53500d08dfc224868942f2ea6202f0fa7c352ff
parent6fcb9e6dfd4df89062b62365659592948c247a67 (diff)
downloaddsub-cb9befec2a3c57c48b87b0f01cc086dd6bf83730.tar.gz
dsub-cb9befec2a3c57c48b87b0f01cc086dd6bf83730.tar.bz2
dsub-cb9befec2a3c57c48b87b0f01cc086dd6bf83730.zip
Make Jukebox routes reflect volume changes correctly
-rw-r--r--src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java21
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java4
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java10
-rw-r--r--src/github/daneren2005/dsub/service/JukeboxController.java4
-rw-r--r--src/github/daneren2005/dsub/service/RemoteController.java1
5 files changed, 37 insertions, 3 deletions
diff --git a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
index d599b784..f4a8bed9 100644
--- a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
+++ b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
@@ -30,12 +30,14 @@ import android.support.v7.media.MediaRouteProviderDescriptor;
import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.service.DownloadService;
+import github.daneren2005.dsub.service.RemoteController;
/**
* Created by Scott on 11/28/13.
*/
public class JukeboxRouteProvider extends MediaRouteProvider {
public static final String CATEGORY_JUKEBOX_ROUTE = "github.daneren2005.dsub.SERVER_JUKEBOX";
+ private RemoteController controller;
private static final int MAX_VOLUME = 10;
private DownloadService downloadService;
@@ -44,6 +46,10 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
super(context);
this.downloadService = (DownloadService) context;
+ broadcastDescriptor();
+ }
+
+ private void broadcastDescriptor() {
// Create intents
IntentFilter routeIntentFilter = new IntentFilter();
routeIntentFilter.addCategory(CATEGORY_JUKEBOX_ROUTE);
@@ -57,7 +63,7 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
.setPlaybackStream(AudioManager.STREAM_MUSIC)
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
.setDescription("Subsonic Jukebox")
- .setVolume(5)
+ .setVolume(controller == null ? 5 : (int) (controller.getVolume() * 10))
.setVolumeMax(MAX_VOLUME)
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
@@ -72,7 +78,7 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
return new JukeboxRouteController(downloadService);
}
- private static class JukeboxRouteController extends RouteController {
+ private class JukeboxRouteController extends RouteController {
private DownloadService downloadService;
public JukeboxRouteController(DownloadService downloadService) {
@@ -91,16 +97,27 @@ public class JukeboxRouteProvider extends MediaRouteProvider {
@Override
public void onRelease() {
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ controller = null;
}
@Override
public void onSelect() {
downloadService.setRemoteEnabled(RemoteControlState.JUKEBOX_SERVER);
+ controller = downloadService.getRemoteController();
}
@Override
public void onUnselect() {
downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ controller = null;
+ }
+
+ @Override
+ public void onUpdateVolume(int delta) {
+ if(controller != null) {
+ controller.setVolume(delta > 0);
+ }
+ broadcastDescriptor();
}
}
}
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index 0ba84c91..5b5a8c6e 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -213,6 +213,10 @@ public class ChromeCastController extends RemoteController {
Log.e(TAG, "Failed to the volume");
}
}
+ @Override
+ public double getVolume() {
+ return Cast.CastApi.getVolume(apiClient);
+ }
@Override
public int getRemotePosition() {
diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java
index b695fd72..19c7a44a 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -1114,6 +1114,10 @@ public class DownloadService extends Service {
return remoteState != RemoteControlState.LOCAL;
}
+ public RemoteController getRemoteController() {
+ return remoteController;
+ }
+
public void setRemoteEnabled(RemoteControlState newState) {
if(instance != null) {
setRemoteEnabled(newState, null);
@@ -1236,7 +1240,11 @@ public class DownloadService extends Service {
}
public void setRemoteVolume(boolean up) {
- remoteController.setVolume(up);
+ if(remoteState == RemoteControlState.JUKEBOX_SERVER) {
+ mediaRouter.getSelectedRoute().requestUpdateVolume(up ? 1 : -1);
+ } else {
+ remoteController.setVolume(up);
+ }
}
public void startRemoteScan() {
diff --git a/src/github/daneren2005/dsub/service/JukeboxController.java b/src/github/daneren2005/dsub/service/JukeboxController.java
index ebebbaf8..09591933 100644
--- a/src/github/daneren2005/dsub/service/JukeboxController.java
+++ b/src/github/daneren2005/dsub/service/JukeboxController.java
@@ -134,6 +134,10 @@ public class JukeboxController extends RemoteController {
tasks.remove(SetGain.class);
tasks.add(new SetGain(gain));
}
+ @Override
+ public double getVolume() {
+ return gain;
+ }
@Override
public int getRemotePosition() {
diff --git a/src/github/daneren2005/dsub/service/RemoteController.java b/src/github/daneren2005/dsub/service/RemoteController.java
index e41a37ad..401fc516 100644
--- a/src/github/daneren2005/dsub/service/RemoteController.java
+++ b/src/github/daneren2005/dsub/service/RemoteController.java
@@ -47,6 +47,7 @@ public abstract class RemoteController {
public abstract void changePosition(int seconds);
public abstract void changeTrack(int index, DownloadFile song);
public abstract void setVolume(boolean up);
+ public abstract double getVolume();
public abstract int getRemotePosition();
public int getRemoteDuration() {