aboutsummaryrefslogtreecommitdiff
path: root/src/github/daneren2005
diff options
context:
space:
mode:
Diffstat (limited to 'src/github/daneren2005')
-rw-r--r--src/github/daneren2005/dsub/activity/SubsonicActivity.java2
-rw-r--r--src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java29
-rw-r--r--src/github/daneren2005/dsub/service/ChromeCastController.java17
-rw-r--r--src/github/daneren2005/dsub/service/DownloadService.java28
-rw-r--r--src/github/daneren2005/dsub/service/JukeboxController.java14
-rw-r--r--src/github/daneren2005/dsub/service/RemoteController.java4
-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
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java82
11 files changed, 121 insertions, 97 deletions
diff --git a/src/github/daneren2005/dsub/activity/SubsonicActivity.java b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
index 154f7f24..646fa295 100644
--- a/src/github/daneren2005/dsub/activity/SubsonicActivity.java
+++ b/src/github/daneren2005/dsub/activity/SubsonicActivity.java
@@ -350,7 +350,7 @@ public class SubsonicActivity extends ActionBarActivity implements OnItemSelecte
boolean isJukebox = getDownloadService() != null && getDownloadService().isRemoteEnabled();
if (isVolumeAdjust && isJukebox) {
- getDownloadService().setRemoteVolume(isVolumeUp);
+ getDownloadService().updateRemoteVolume(isVolumeUp);
return true;
}
return super.onKeyDown(keyCode, event);
diff --git a/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java b/src/github/daneren2005/dsub/provider/JukeboxRouteProvider.java
index d599b784..0d2a5ff5 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,35 @@ 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.updateVolume(delta > 0);
+ }
+ broadcastDescriptor();
+ }
+
+ @Override
+ public void onSetVolume(int volume) {
+ if(controller != null) {
+ controller.setVolume(volume);
+ }
+ broadcastDescriptor();
}
}
}
diff --git a/src/github/daneren2005/dsub/service/ChromeCastController.java b/src/github/daneren2005/dsub/service/ChromeCastController.java
index 0ba84c91..7568fe4d 100644
--- a/src/github/daneren2005/dsub/service/ChromeCastController.java
+++ b/src/github/daneren2005/dsub/service/ChromeCastController.java
@@ -200,7 +200,18 @@ public class ChromeCastController extends RemoteController {
}
@Override
- public void setVolume(boolean up) {
+ public void setVolume(int volume) {
+ gain = volume / 10.0;
+
+ getVolumeToast().setVolume((float) gain);
+ try {
+ Cast.CastApi.setVolume(apiClient, gain);
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to the volume");
+ }
+ }
+ @Override
+ public void updateVolume(boolean up) {
double delta = up ? 0.1 : -0.1;
gain += delta;
gain = Math.max(gain, 0.0);
@@ -213,6 +224,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 8fecc893..66295d5e 100644
--- a/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/src/github/daneren2005/dsub/service/DownloadService.java
@@ -30,7 +30,6 @@ import static github.daneren2005.dsub.domain.PlayerState.STOPPED;
import github.daneren2005.dsub.audiofx.AudioEffectsController;
import github.daneren2005.dsub.audiofx.EqualizerController;
-import github.daneren2005.dsub.audiofx.LoudnessEnhancerController;
import github.daneren2005.dsub.audiofx.VisualizerController;
import github.daneren2005.dsub.domain.Bookmark;
import github.daneren2005.dsub.domain.MusicDirectory;
@@ -70,9 +69,9 @@ 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;
/**
* @author Sindre Mehus
@@ -1113,6 +1112,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);
@@ -1227,8 +1230,19 @@ public class DownloadService extends Service {
}
}
- public void setRemoteVolume(boolean up) {
- remoteController.setVolume(up);
+ public void registerRoute(MediaRouter router) {
+ mRemoteControl.registerRoute(router);
+ }
+ public void unregisterRoute(MediaRouter router) {
+ mRemoteControl.unregisterRoute(router);
+ }
+
+ public void updateRemoteVolume(boolean up) {
+ if(remoteState == RemoteControlState.JUKEBOX_SERVER) {
+ mediaRouter.getSelectedRoute().requestUpdateVolume(up ? 1 : -1);
+ } else {
+ remoteController.updateVolume(up);
+ }
}
public void startRemoteScan() {
@@ -1518,7 +1532,11 @@ public class DownloadService extends Service {
private void handleError(Exception x) {
Log.w(TAG, "Media player error: " + x, x);
if(mediaPlayer != null) {
- mediaPlayer.reset();
+ try {
+ mediaPlayer.reset();
+ } catch(Exception e) {
+ Log.e(TAG, "Failed to reset player in error handler");
+ }
}
setPlayerState(IDLE);
}
diff --git a/src/github/daneren2005/dsub/service/JukeboxController.java b/src/github/daneren2005/dsub/service/JukeboxController.java
index ebebbaf8..da1538be 100644
--- a/src/github/daneren2005/dsub/service/JukeboxController.java
+++ b/src/github/daneren2005/dsub/service/JukeboxController.java
@@ -124,7 +124,15 @@ public class JukeboxController extends RemoteController {
downloadService.setPlayerState(PlayerState.STARTED);
}
@Override
- public void setVolume(boolean up) {
+ public void setVolume(int volume) {
+ gain = volume / 10.0f;
+
+ getVolumeToast().setVolume(gain);
+ tasks.remove(SetGain.class);
+ tasks.add(new SetGain(gain));
+ }
+ @Override
+ public void updateVolume(boolean up) {
float delta = up ? 0.1f : -0.1f;
gain += delta;
gain = Math.max(gain, 0.0f);
@@ -134,6 +142,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..d5a4d8df 100644
--- a/src/github/daneren2005/dsub/service/RemoteController.java
+++ b/src/github/daneren2005/dsub/service/RemoteController.java
@@ -46,7 +46,9 @@ public abstract class RemoteController {
public abstract void updatePlaylist();
public abstract void changePosition(int seconds);
public abstract void changeTrack(int index, DownloadFile song);
- public abstract void setVolume(boolean up);
+ public abstract void setVolume(int volume);
+ public abstract void updateVolume(boolean up);
+ public abstract double getVolume();
public abstract int getRemotePosition();
public int getRemoteDuration() {
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())
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java
deleted file mode 100644
index 532aec5b..00000000
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientKK.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package github.daneren2005.dsub.util.compat;
-
-import github.daneren2005.dsub.domain.MusicDirectory;
-import github.daneren2005.dsub.util.ImageLoader;
-import android.annotation.TargetApi;
-import android.app.PendingIntent;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.media.AudioManager;
-import android.media.MediaMetadataEditor;
-import android.media.MediaMetadataRetriever;
-import android.media.Rating;
-import android.media.RemoteControlClient;
-import android.os.AsyncTask;
-import android.util.Log;
-
-import github.daneren2005.dsub.activity.SubsonicActivity;
-import github.daneren2005.dsub.service.DownloadService;
-import github.daneren2005.dsub.service.MusicService;
-import github.daneren2005.dsub.service.MusicServiceFactory;
-import github.daneren2005.dsub.util.SilentBackgroundTask;
-import github.daneren2005.dsub.util.Util;
-import java.io.File;
-import java.util.Arrays;
-
-@TargetApi(19)
-public class RemoteControlClientKK extends RemoteControlClientJB {
- private static String TAG = RemoteControlClientKK.class.getSimpleName();
- protected MusicDirectory.Entry currentSong;
-
- @Override
- public void register(final Context context, final ComponentName mediaButtonReceiverComponent) {
- super.register(context, mediaButtonReceiverComponent);
-
- mRemoteControl.setMetadataUpdateListener(new RemoteControlClient.OnMetadataUpdateListener() {
- @Override
- public void onMetadataUpdate(int key, Object newValue) {
- if(key == MediaMetadataEditor.RATING_KEY_BY_USER) {
- Rating rating = (Rating) newValue;
- setStarred(currentSong, rating.hasHeart());
- }
- }
- });
- }
-
- @Override
- protected void updateMetadata(final MusicDirectory.Entry currentSong, final RemoteControlClient.MetadataEditor editor) {
- super.updateMetadata(currentSong, editor);
- editor.putObject(MediaMetadataEditor.RATING_KEY_BY_USER, Rating.newHeartRating(currentSong.isStarred()));
- editor.addEditableKey(MediaMetadataEditor.RATING_KEY_BY_USER);
- this.currentSong = currentSong;
- }
-
- @Override
- protected int getTransportFlags() {
- return super.getTransportFlags() | RemoteControlClient.FLAG_KEY_MEDIA_RATING;
- }
-
- private void setStarred(final MusicDirectory.Entry entry, final boolean starred) {
- entry.setStarred(starred);
-
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- try {
- MusicService musicService = MusicServiceFactory.getMusicService(downloadService);
- musicService.setStarred(Arrays.asList(entry.getId()), null, null, starred, downloadService, null);
-
- // Make sure to clear parent cache
- String s = Util.getRestUrl(downloadService, null) + entry.getParent();
- String parentCache = "directory-" + s.hashCode() + ".ser";
- File file = new File(downloadService.getCacheDir(), parentCache);
- file.delete();
- } catch(Exception e) {
- Log.w(TAG, "Failed to set star for " + entry.getTitle());
- }
- return null;
- }
- }.execute();
- }
-}