aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-08-12 20:36:36 -0700
committerScott Jackson <daneren2005@gmail.com>2013-08-12 20:36:36 -0700
commit1ff77070d5ef8fe9a8d72560f1af6ff72584cd0f (patch)
treefebb1f50cfef4ef74d88c4222c9b692d0cfad658 /src
parent8e30b9706587ed9f3b2609719e67951be06d5ea8 (diff)
parent645e6d1e17444b612380b2d9515e3283cc867290 (diff)
downloaddsub-1ff77070d5ef8fe9a8d72560f1af6ff72584cd0f.tar.gz
dsub-1ff77070d5ef8fe9a8d72560f1af6ff72584cd0f.tar.bz2
dsub-1ff77070d5ef8fe9a8d72560f1af6ff72584cd0f.zip
Merge branch 'master' of https://github.com/daneren2005/Subsonic
Diffstat (limited to 'src')
-rw-r--r--src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java54
1 files changed, 44 insertions, 10 deletions
diff --git a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
index 732f96da..1ccf3c72 100644
--- a/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
+++ b/src/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
@@ -10,15 +10,19 @@ import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.RemoteControlClient;
+import android.os.Build;
import github.daneren2005.dsub.activity.SubsonicActivity;
+import github.daneren2005.dsub.service.DownloadService;
@TargetApi(14)
public class RemoteControlClientICS extends RemoteControlClientHelper {
private RemoteControlClient mRemoteControl;
private ImageLoader imageLoader;
+ private DownloadService downloadService;
public void register(final Context context, final ComponentName mediaButtonReceiverComponent) {
+ downloadService = (DownloadService) context;
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
// build the PendingIntent for the remote control client
@@ -31,16 +35,23 @@ public class RemoteControlClientICS extends RemoteControlClientHelper {
audioManager.registerRemoteControlClient(mRemoteControl);
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
-
- mRemoteControl.setTransportControlFlags(
- RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
- RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
- RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
- RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
- RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
- RemoteControlClient.FLAG_KEY_MEDIA_STOP);
-
+ mRemoteControl.setTransportControlFlags(getTransportFlags());
imageLoader = SubsonicActivity.getStaticImageLoader(context);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ mRemoteControl.setOnGetPlaybackPositionListener(new RemoteControlClient.OnGetPlaybackPositionListener() {
+ @Override
+ long onGetPlaybackPosition() {
+ return downloadService.getPlayerPosition();
+ }
+ });
+ mRemoteControl.setPlaybackPositionUpdateListener(new RemoteControlClient.OnPlaybackPositionUpdateListener() {
+ @Override
+ void onPlaybackPositionUpdate(long newPosition) {
+ downloadService.seekTo(newPosition);
+ }
+ });
+ }
}
public void unregister(final Context context) {
@@ -51,7 +62,15 @@ public class RemoteControlClientICS extends RemoteControlClientHelper {
}
public void setPlaybackState(final int state) {
- mRemoteControl.setPlaybackState(state);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ long position = -1;
+ if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
+ position = downloadService.getPlayerPosition();
+ }
+ mRemoteControl.setPlaybackState(state, position, 1.0f);
+ } else {
+ mRemoteControl.setPlaybackState(state);
+ }
}
public void updateMetadata(final Context context, final MusicDirectory.Entry currentSong) {
@@ -79,5 +98,20 @@ public class RemoteControlClientICS extends RemoteControlClientHelper {
imageLoader.loadImage(context, mRemoteControl, currentSong);
}
}
+
+ private int getTransportFlags() {
+ int flags = RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
+ RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
+ RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE |
+ RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
+ RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
+ RemoteControlClient.FLAG_KEY_MEDIA_STOP;
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
+ flags = flags | RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE;
+ }
+
+ return flags;
+ }
}