2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-01 06:35:09 +00:00

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
This commit is contained in:
Matthijs Tijink
2018-02-24 17:14:30 +01:00
parent c8dbbb1fe8
commit 1c3e6f84a7
2 changed files with 11 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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);