From 1c3e6f84a75e98b157b71865de11c5514f826709 Mon Sep 17 00:00:00 2001 From: Matthijs Tijink Date: Sat, 24 Feb 2018 17:14:30 +0100 Subject: [PATCH] Add album art to media notification and lock screen Summary: Adds the album art to the media notification and lock screen. How it looks on my phone (disregard the somewhat weird look, that's just the weird UI my phone vendor uses): {F5728066} Google images shows how it'll look on other phones (this one includes the lock screen image): {F5728069} And Android Oreo automatically colors the notification based on the album art color (untested, but should work): {F5728070} Test Plan: Changes are minor and it works fine for me. Reviewers: #kde_connect, nicolasfella, albertvaka Reviewed By: #kde_connect, nicolasfella, albertvaka Subscribers: nicolasfella Differential Revision: https://phabricator.kde.org/D10798 --- .../kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java | 6 +----- .../Plugins/MprisPlugin/MprisMediaSession.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java index 733e0c18..7f18f3b3 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java @@ -163,11 +163,7 @@ public final class AlbumArtCache { try { DiskLruCache.Snapshot item = diskCache.get(urlToDiskCacheKey(albumUrl)); if (item != null) { - BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); - decodeOptions.inScaled = false; - decodeOptions.inDensity = 1; - decodeOptions.inTargetDensity = 1; - Bitmap result = BitmapFactory.decodeStream(item.getInputStream(0), null, decodeOptions); + Bitmap result = BitmapFactory.decodeStream(item.getInputStream(0)); item.close(); MemoryCacheItem memItem = new MemoryCacheItem(); if (result != null) { diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisMediaSession.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisMediaSession.java index e5470361..207f4ea5 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisMediaSession.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisMediaSession.java @@ -25,6 +25,7 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Bitmap; import android.os.Handler; import android.os.Looper; import android.os.Message; @@ -253,6 +254,11 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh metadata.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, notificationPlayer.getLength()); } + Bitmap albumArt = notificationPlayer.getAlbumArt(); + if (albumArt != null) { + metadata.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, albumArt); + } + mediaSession.setMetadata(metadata.build()); PlaybackStateCompat.Builder playbackState = new PlaybackStateCompat.Builder(); @@ -326,6 +332,10 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh notification.setContentText(notificationPlayer.getPlayer()); } + if (albumArt != null) { + notification.setLargeIcon(albumArt); + } + if (!notificationPlayer.isPlaying()) { Intent iCloseNotification = new Intent(service, MprisMediaNotificationReceiver.class); iCloseNotification.setAction(MprisMediaNotificationReceiver.ACTION_CLOSE_NOTIFICATION);