aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java')
-rw-r--r--src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
new file mode 100644
index 00000000..eaefbf55
--- /dev/null
+++ b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
@@ -0,0 +1,106 @@
+/*
+ This file is part of Subsonic.
+
+ Subsonic is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Subsonic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
+
+ Copyright 2014 (C) Scott Jackson
+*/
+package github.daneren2005.dsub.provider;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.media.AudioManager;
+import android.media.MediaRouter;
+import android.support.v7.media.MediaControlIntent;
+import android.support.v7.media.MediaRouteDescriptor;
+import android.support.v7.media.MediaRouteProvider;
+import android.support.v7.media.MediaRouteProviderDescriptor;
+
+import github.daneren2005.dsub.domain.RemoteControlState;
+import github.daneren2005.dsub.service.DownloadService;
+
+/**
+ * Created by Scott on 11/28/13.
+ */
+public class JukeboxRouteProvider extends MediaRouteProvider {
+ public static final String CATEGORY_SAMPLE_ROUTE = "github.daneren2005.dsub.SERVER_JUKEBOX";
+ private static int MAX_VOLUME = 10;
+
+ private DownloadService downloadService;
+
+ public JukeboxRouteProvider(Context context) {
+ super(context);
+ this.downloadService = (DownloadService) context;
+
+ // Create intents
+ IntentFilter routeIntentFilter = new IntentFilter();
+ routeIntentFilter.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
+ routeIntentFilter.addAction(MediaControlIntent.ACTION_START_SESSION);
+ routeIntentFilter.addAction(MediaControlIntent.ACTION_GET_SESSION_STATUS);
+ routeIntentFilter.addAction(MediaControlIntent.ACTION_END_SESSION);
+
+ // Create route descriptor
+ MediaRouteDescriptor.Builder routeBuilder = new MediaRouteDescriptor.Builder("Jukebox Route", "Subsonic Jukebox");
+ routeBuilder.addControlFilter(routeIntentFilter)
+ .setPlaybackStream(AudioManager.STREAM_MUSIC)
+ .setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
+ .setDescription("Subsonic Jukebox")
+ .setVolume(5)
+ .setVolumeMax(MAX_VOLUME)
+ .setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE);
+
+ // Create descriptor
+ MediaRouteProviderDescriptor.Builder providerBuilder = new MediaRouteProviderDescriptor.Builder();
+ providerBuilder.addRoute(routeBuilder.build());
+ setDescriptor(providerBuilder.build());
+ }
+
+ @Override
+ public MediaRouteProvider.RouteController onCreateRouteController(String routeId) {
+ return new JukeboxRouteController(downloadService);
+ }
+
+ private static class JukeboxRouteController extends RouteController {
+ private DownloadService downloadService;
+
+ public JukeboxRouteController(DownloadService downloadService) {
+ this.downloadService = downloadService;
+ }
+
+ @Override
+ public boolean onControlRequest(Intent intent, android.support.v7.media.MediaRouter.ControlRequestCallback callback) {
+ if (intent.hasCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public void onRelease() {
+ downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ }
+
+ @Override
+ public void onSelect() {
+ downloadService.setRemoteEnabled(RemoteControlState.JUKEBOX_SERVER);
+ }
+
+ @Override
+ public void onUnselect() {
+ downloadService.setRemoteEnabled(RemoteControlState.LOCAL);
+ }
+ }
+}