diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-02-08 21:42:25 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-02-08 21:42:25 -0800 |
commit | fb69cf8533c74483e873804d9f980e242d737c62 (patch) | |
tree | df3e4890c5a291fcff2d77c69e9458b761048f4a | |
parent | 4b10c991618aabb2343f49b3f52cb2c697f426cf (diff) | |
download | dsub-fb69cf8533c74483e873804d9f980e242d737c62.tar.gz dsub-fb69cf8533c74483e873804d9f980e242d737c62.tar.bz2 dsub-fb69cf8533c74483e873804d9f980e242d737c62.zip |
Converted RC from button to MediaRoute + added Chromecast requires
-rw-r--r-- | Subsonic.iml | 3 | ||||
-rw-r--r-- | libs/android-support-v7-mediarouter.jar | bin | 0 -> 168050 bytes | |||
-rw-r--r-- | project.properties | 4 | ||||
-rw-r--r-- | res/layout-land/download.xml | 5 | ||||
-rw-r--r-- | res/layout-port/download.xml | 5 | ||||
-rw-r--r-- | res/menu/nowplaying.xml | 7 | ||||
-rw-r--r-- | res/values/strings.xml | 1 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/fragments/DownloadFragment.java | 25 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java | 106 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadService.java | 4 | ||||
-rw-r--r-- | src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 19 |
11 files changed, 149 insertions, 30 deletions
diff --git a/Subsonic.iml b/Subsonic.iml index f7983073..f9f7ef9c 100644 --- a/Subsonic.iml +++ b/Subsonic.iml @@ -14,10 +14,13 @@ <sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" generated="true" />
</content>
<orderEntry type="library" name="libs1" level="project" />
+ <orderEntry type="library" name="google-play-services" level="project" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="appcompat" />
<orderEntry type="module" module-name="DragSortListView" />
+ <orderEntry type="module" module-name="mediarouter" />
+ <orderEntry type="module" module-name="google-play-services_lib" />
</component>
</module>
diff --git a/libs/android-support-v7-mediarouter.jar b/libs/android-support-v7-mediarouter.jar Binary files differnew file mode 100644 index 00000000..07c1aa6d --- /dev/null +++ b/libs/android-support-v7-mediarouter.jar diff --git a/project.properties b/project.properties index 73506e5d..80f83a52 100644 --- a/project.properties +++ b/project.properties @@ -10,4 +10,6 @@ # Project target. target=android-19 android.library.reference.1=../../../../Program Files (x86)/Android/android-sdk/extras/android/support/v7/appcompat -android.library.reference.2=DragSortListView/library
\ No newline at end of file +android.library.reference.2=DragSortListView/library +android.library.reference.3=../../../../Program Files (x86)/Android/android-sdk/extras/android/support/v7/mediarouter +android.library.reference.4=../../../../Program Files (x86)/Android/android-sdk/extras/google/google_play_services/libproject/google-play-services_lib
\ No newline at end of file diff --git a/res/layout-land/download.xml b/res/layout-land/download.xml index c71ff4b7..dfdb126a 100644 --- a/res/layout-land/download.xml +++ b/res/layout-land/download.xml @@ -48,11 +48,6 @@ android:layout_gravity="center_horizontal">
<Button
- android:id="@+id/download_jukebox"
- android:text="RC"
- style="@style/DownloadActionButton"/>
-
- <Button
android:id="@+id/download_equalizer"
android:text="EQ"
style="@style/DownloadActionButton"/>
diff --git a/res/layout-port/download.xml b/res/layout-port/download.xml index 7d89baf3..7aa83fb5 100644 --- a/res/layout-port/download.xml +++ b/res/layout-port/download.xml @@ -57,11 +57,6 @@ android:layout_gravity="center_horizontal">
<Button
- android:id="@+id/download_jukebox"
- android:text="RC"
- style="@style/DownloadActionButton"/>
-
- <Button
android:id="@+id/download_equalizer"
android:text="EQ"
style="@style/DownloadActionButton"/>
diff --git a/res/menu/nowplaying.xml b/res/menu/nowplaying.xml index 3c9c5ba6..b67ecf64 100644 --- a/res/menu/nowplaying.xml +++ b/res/menu/nowplaying.xml @@ -6,6 +6,13 @@ android:icon="?attr/shuffle" android:title="@string/download.menu_shuffle" compat:showAsAction="ifRoom|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" diff --git a/res/values/strings.xml b/res/values/strings.xml index 1d4398f5..de4070bb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -84,6 +84,7 @@ <string name="menu.show_artist">Show Artist</string>
<string name="menu.share">Share</string>
<string name="menu.delete_cache">Delete Cache</string>
+ <string name="menu.cast">Cast To Device</string>
<string name="playlist.label">Playlists</string>
<string name="playlist.update_info">Update Information</string>
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; } |