aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-10-10 15:35:02 -0700
committerScott Jackson <daneren2005@gmail.com>2015-10-10 15:35:02 -0700
commit8fed2b7596b2f0b2ba0e7d650f454267f3b1e351 (patch)
tree833df83c702d5250144ce3007d7fb6e4e36b72c4
parent4863fd70fc687e6ad85d718fc37882a6607f3ce6 (diff)
downloaddsub-8fed2b7596b2f0b2ba0e7d650f454267f3b1e351.tar.gz
dsub-8fed2b7596b2f0b2ba0e7d650f454267f3b1e351.tar.bz2
dsub-8fed2b7596b2f0b2ba0e7d650f454267f3b1e351.zip
#480 Add support for back/forward + album artwork for Auto
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java27
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java14
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java41
4 files changed, 64 insertions, 20 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
index 8b027d70..470d72fb 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/ImageLoader.java
@@ -29,7 +29,6 @@ import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
-import android.media.RemoteControlClient;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
@@ -46,6 +45,7 @@ import github.daneren2005.dsub.domain.Playlist;
import github.daneren2005.dsub.domain.ServerInfo;
import github.daneren2005.dsub.service.MusicService;
import github.daneren2005.dsub.service.MusicServiceFactory;
+import github.daneren2005.dsub.util.compat.RemoteControlClientBase;
/**
* Asynchronous loading of images, with caching.
@@ -257,22 +257,22 @@ public class ImageLoader {
return task;
}
- public SilentBackgroundTask<Void> loadImage(Context context, RemoteControlClient remoteControl, MusicDirectory.Entry entry) {
+ public SilentBackgroundTask<Void> loadImage(Context context, RemoteControlClientBase remoteControl, MusicDirectory.Entry entry) {
Bitmap bitmap;
if (entry == null || entry.getCoverArt() == null) {
bitmap = getUnknownImage(entry, imageSizeLarge);
- setImage(remoteControl, Util.createDrawableFromBitmap(context, bitmap));
+ setImage(entry, remoteControl, Util.createDrawableFromBitmap(context, bitmap));
return null;
}
bitmap = cache.get(getKey(entry.getCoverArt(), imageSizeLarge));
if (bitmap != null && !bitmap.isRecycled()) {
Drawable drawable = Util.createDrawableFromBitmap(this.context, bitmap);
- setImage(remoteControl, drawable);
+ setImage(entry, remoteControl, drawable);
return null;
}
- setImage(remoteControl, Util.createDrawableFromBitmap(context, null));
+ setImage(entry, remoteControl, Util.createDrawableFromBitmap(context, null));
ImageTask task = new RemoteControlClientImageTask(context, entry, imageSizeLarge, imageSizeLarge, false, remoteControl);
task.execute();
return task;
@@ -367,28 +367,27 @@ public class ImageLoader {
}
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
- private void setImage(RemoteControlClient remoteControl, Drawable drawable) {
+ private void setImage(MusicDirectory.Entry entry, RemoteControlClientBase remoteControl, Drawable drawable) {
if(remoteControl != null && drawable != null) {
Bitmap origBitmap = ((BitmapDrawable)drawable).getBitmap();
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && origBitmap != null) {
origBitmap = origBitmap.copy(origBitmap.getConfig(), false);
}
if ( origBitmap != null && !origBitmap.isRecycled()) {
- remoteControl.editMetadata(false).putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, origBitmap).apply();
+ remoteControl.updateAlbumArt(entry, origBitmap);
} else {
if(origBitmap != null) {
Log.e(TAG, "Tried to load a recycled bitmap.");
}
- remoteControl.editMetadata(false)
- .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null)
- .apply();
+
+ remoteControl.updateAlbumArt(entry, null);
}
}
}
public abstract class ImageTask extends SilentBackgroundTask<Void> {
private final Context mContext;
- private final MusicDirectory.Entry mEntry;
+ protected final MusicDirectory.Entry mEntry;
private final int mSize;
private final int mSaveSize;
private final boolean mIsNowPlaying;
@@ -448,9 +447,9 @@ public class ImageLoader {
}
private class RemoteControlClientImageTask extends ImageTask {
- private RemoteControlClient mRemoteControl;
+ private RemoteControlClientBase mRemoteControl;
- public RemoteControlClientImageTask(Context context, MusicDirectory.Entry entry, int size, int saveSize, boolean isNowPlaying, RemoteControlClient remoteControl) {
+ public RemoteControlClientImageTask(Context context, MusicDirectory.Entry entry, int size, int saveSize, boolean isNowPlaying, RemoteControlClientBase remoteControl) {
super(context, entry, size, saveSize, isNowPlaying);
mRemoteControl = remoteControl;
@@ -458,7 +457,7 @@ public class ImageLoader {
@Override
protected void done(Void result) {
- setImage(mRemoteControl, mDrawable);
+ setImage(mEntry, mRemoteControl, mDrawable);
}
}
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
index 357e2585..b5987270 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientBase.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientBase.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.graphics.Bitmap;
import android.support.v7.media.MediaRouter;
import android.os.Build;
@@ -26,6 +27,7 @@ public abstract class RemoteControlClientBase {
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 updateAlbumArt(MusicDirectory.Entry currentSong, Bitmap bitmap);
public abstract void registerRoute(MediaRouter router);
public abstract void unregisterRoute(MediaRouter router);
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
index 9b4725bd..994c23a6 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientICS.java
@@ -8,6 +8,7 @@ import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
import android.media.AudioManager;
import android.media.MediaMetadataRetriever;
import android.media.RemoteControlClient;
@@ -72,15 +73,20 @@ public class RemoteControlClientICS extends RemoteControlClientBase {
updateMetadata(currentSong, editor);
editor.apply();
if (currentSong == null || imageLoader == null) {
- mRemoteControl.editMetadata(true)
- .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, null)
- .apply();
+ updateAlbumArt(currentSong, null);
} else {
- imageLoader.loadImage(context, mRemoteControl, currentSong);
+ imageLoader.loadImage(context, this, currentSong);
}
}
@Override
+ public void updateAlbumArt(MusicDirectory.Entry currentSong, Bitmap bitmap) {
+ mRemoteControl.editMetadata(true)
+ .putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, bitmap).
+ apply();
+ }
+
+ @Override
public void registerRoute(MediaRouter router) {
if(mRemoteControl == null) {
return;
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
index 2cf2dd20..8ebbc9de 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
@@ -23,6 +23,7 @@ import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.media.MediaMetadata;
import android.media.Rating;
@@ -31,16 +32,22 @@ import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.os.Build;
import android.support.v7.media.MediaRouter;
+import android.util.Log;
+import github.daneren2005.dsub.activity.SubsonicActivity;
import github.daneren2005.dsub.activity.SubsonicFragmentActivity;
import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.service.DownloadService;
import github.daneren2005.dsub.util.Constants;
+import github.daneren2005.dsub.util.ImageLoader;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class RemoteControlClientLP extends RemoteControlClientBase {
- private MediaSession mediaSession;
- private DownloadService downloadService;
+ private static final String TAG = RemoteControlClientLP.class.getSimpleName();
+
+ protected MediaSession mediaSession;
+ protected DownloadService downloadService;
+ protected ImageLoader imageLoader;
private PlaybackState previousState;
@@ -72,6 +79,8 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
mediaSession.setPlaybackToLocal(audioAttributesBuilder.build());
mediaSession.setActive(true);
+
+ imageLoader = SubsonicActivity.getStaticImageLoader(context);
}
@Override
@@ -118,6 +127,14 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
@Override
public void updateMetadata(Context context, MusicDirectory.Entry currentSong) {
+ setMetadata(currentSong, null);
+
+ if(currentSong != null && imageLoader != null) {
+ imageLoader.loadImage(context, this, currentSong);
+ }
+ }
+
+ public void setMetadata(MusicDirectory.Entry currentSong, Bitmap bitmap) {
MediaMetadata.Builder builder = new MediaMetadata.Builder();
builder.putString(MediaMetadata.METADATA_KEY_ARTIST, (currentSong == null) ? null : currentSong.getArtist())
.putString(MediaMetadata.METADATA_KEY_ALBUM, (currentSong == null) ? null : currentSong.getAlbum())
@@ -140,10 +157,19 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
builder.putRating(MediaMetadata.METADATA_KEY_USER_RATING, rating);
+ if(bitmap != null) {
+ builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
+ }
+
mediaSession.setMetadata(builder.build());
}
@Override
+ public void updateAlbumArt(MusicDirectory.Entry currentSong, Bitmap bitmap) {
+ setMetadata(currentSong, bitmap);
+ }
+
+ @Override
public void registerRoute(MediaRouter router) {
router.setMediaSession(mediaSession);
}
@@ -161,6 +187,8 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
return PlaybackState.ACTION_PLAY |
PlaybackState.ACTION_PAUSE |
PlaybackState.ACTION_SEEK_TO |
+ PlaybackState.ACTION_SKIP_TO_NEXT |
+ PlaybackState.ACTION_SKIP_TO_PREVIOUS |
PlaybackState.ACTION_SET_RATING;
}
@@ -186,6 +214,15 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
}
@Override
+ public void onSkipToNext() {
+ downloadService.next();
+ }
+ @Override
+ public void onSkipToPrevious() {
+ downloadService.previous();
+ }
+
+ @Override
public void onSetRating(Rating rating) {
if(rating.getRatingStyle() != Rating.RATING_THUMB_UP_DOWN) {
return;