diff options
Diffstat (limited to 'src')
4 files changed, 135 insertions, 19 deletions
diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index d7f58e88..c5be820c 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -13,6 +13,7 @@ import android.content.SharedPreferences; import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
+import android.support.v7.app.MediaRouteButton;
import android.view.ContextMenu;
import android.view.Display;
import android.view.GestureDetector;
@@ -41,7 +42,6 @@ import github.daneren2005.dsub.R; import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.PlayerState;
-import github.daneren2005.dsub.domain.RemoteControlState;
import github.daneren2005.dsub.domain.RepeatMode;
import github.daneren2005.dsub.service.DownloadFile;
import github.daneren2005.dsub.service.DownloadService;
@@ -88,7 +88,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe private ImageButton repeatButton;
private Button equalizerButton;
private Button visualizerButton;
- private Button jukeboxButton;
private View toggleListButton;
private ImageButton starButton;
private ImageButton bookmarkButton;
@@ -170,7 +169,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe repeatButton = (ImageButton)rootView.findViewById(R.id.download_repeat);
equalizerButton = (Button)rootView.findViewById(R.id.download_equalizer);
visualizerButton = (Button)rootView.findViewById(R.id.download_visualizer);
- jukeboxButton = (Button)rootView.findViewById(R.id.download_jukebox);
bookmarkButton = (ImageButton) rootView.findViewById(R.id.download_bookmark);
LinearLayout visualizerViewLayout = (LinearLayout)rootView.findViewById(R.id.download_visualizer_view_layout);
toggleListButton =rootView.findViewById(R.id.download_toggle_list);
@@ -203,7 +201,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe startButton.setOnTouchListener(touchListener);
equalizerButton.setOnTouchListener(touchListener);
visualizerButton.setOnTouchListener(touchListener);
- jukeboxButton.setOnTouchListener(touchListener);
bookmarkButton.setOnTouchListener(touchListener);
emptyTextView.setOnTouchListener(touchListener);
albumArtImageView.setOnTouchListener(touchListener);
@@ -375,17 +372,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe }
});
- jukeboxButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- boolean jukeboxEnabled = !getDownloadService().isRemoteEnabled();
- getDownloadService().setRemoteEnabled(jukeboxEnabled ? RemoteControlState.JUKEBOX_SERVER : RemoteControlState.LOCAL);
- updateButtons();
- Util.toast(context, jukeboxEnabled ? R.string.download_jukebox_on : R.string.download_jukebox_off, false);
- setControlsVisible(true);
- }
- });
-
bookmarkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -516,6 +502,11 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe if(downloadService != null && downloadService.getKeepScreenOn() && nowPlaying) {
menu.findItem(R.id.menu_screen_on_off).setTitle(R.string.download_menu_screen_off);
}
+ if(downloadService != null) {
+ MenuItem mediaRouteItem = menu.findItem(R.id.menu_mediaroute);
+ MediaRouteButton mediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();
+ mediaRouteButton.setRouteSelector(downloadService.getRemotesAvailable());
+ }
}
@Override
@@ -832,9 +823,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe if (visualizerView != null) {
visualizerButton.setTextColor(visualizerView.isActive() ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
}
-
- boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isRemoteEnabled();
- jukeboxButton.setTextColor(jukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
if(Util.isOffline(context)) {
bookmarkButton.setVisibility(View.GONE);
@@ -1195,7 +1183,6 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe break;
}
- jukeboxButton.setTextColor(isJukeboxEnabled ? COLOR_BUTTON_ENABLED : COLOR_BUTTON_DISABLED);
onProgressChangedTask = null;
}
};
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); + } + } +} diff --git a/src/github/daneren2005/dsub/service/DownloadService.java b/src/github/daneren2005/dsub/service/DownloadService.java index 1a254c73..1a96b2be 100644 --- a/src/github/daneren2005/dsub/service/DownloadService.java +++ b/src/github/daneren2005/dsub/service/DownloadService.java @@ -18,6 +18,8 @@ */ package github.daneren2005.dsub.service; +import android.support.v7.media.MediaRouteSelector; + import java.util.List; import github.daneren2005.dsub.audiofx.EqualizerController; @@ -124,6 +126,8 @@ public interface DownloadService { VisualizerController getVisualizerController(); + MediaRouteSelector getRemotesAvailable(); + boolean isRemoteEnabled(); void setRemoteEnabled(RemoteControlState newState); diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 9f1e5ee9..ad2f0490 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -34,6 +34,7 @@ import github.daneren2005.dsub.domain.PlayerState; import github.daneren2005.dsub.domain.PodcastEpisode; import github.daneren2005.dsub.domain.RemoteControlState; import github.daneren2005.dsub.domain.RepeatMode; +import github.daneren2005.dsub.provider.JukeboxRouteProvider; import github.daneren2005.dsub.receiver.MediaButtonIntentReceiver; import github.daneren2005.dsub.util.CancellableTask; import github.daneren2005.dsub.util.Constants; @@ -63,6 +64,9 @@ import android.os.Handler; import android.os.IBinder; import android.os.Looper; import android.os.PowerManager; +import android.support.v7.media.MediaControlIntent; +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; @@ -136,6 +140,8 @@ public class DownloadServiceImpl extends Service implements DownloadService { private int timerDuration; private boolean autoPlayStart = false; + private MediaRouteSelector remoteSelector; + static { if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { equalizerAvailable = true; @@ -210,6 +216,14 @@ public class DownloadServiceImpl extends Service implements DownloadService { getVisualizerController(); showVisualization = true; } + + MediaRouter mediaRouter = MediaRouter.getInstance(this); + JukeboxRouteProvider routeProvider = new JukeboxRouteProvider(this); + mediaRouter.addProvider(routeProvider); + + MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder(); + builder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK); + remoteSelector = builder.build(); } @Override @@ -1118,6 +1132,11 @@ public class DownloadServiceImpl extends Service implements DownloadService { } @Override + public MediaRouteSelector getRemotesAvailable() { + return remoteSelector; + } + + @Override public boolean isRemoteEnabled() { return remoteState != RemoteControlState.LOCAL; } |