diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index 5ad855e78..72a699623 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1626,8 +1626,12 @@ public final class Player implements final boolean showThumbnail = prefs.getBoolean( context.getString(R.string.show_thumbnail_key), true); // setMetadata only updates the metadata when any of the metadata keys are null - mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(), - showThumbnail ? getThumbnail() : null, duration); + if (showThumbnail) { + mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(), getThumbnail(), + duration); + } else { + mediaSessionManager.setMetadata(getVideoTitle(), getUploaderName(), duration); + } } private void startProgressLoop() { @@ -3023,9 +3027,11 @@ public final class Player implements @Nullable public Bitmap getThumbnail() { - return currentThumbnail == null - ? BitmapFactory.decodeResource(context.getResources(), R.drawable.dummy_thumbnail) - : currentThumbnail; + if (currentThumbnail == null) { + currentThumbnail = BitmapFactory.decodeResource( + context.getResources(), R.drawable.dummy_thumbnail); + } + return currentThumbnail; } //endregion diff --git a/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java b/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java index c7f1f9c8c..5bab1cb9a 100644 --- a/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java +++ b/app/src/main/java/org/schabi/newpipe/player/helper/MediaSessionManager.java @@ -65,6 +65,39 @@ public class MediaSessionManager { return mediaSession.getSessionToken(); } + public void setMetadata(final String title, + final String artist, + final long duration) { + if (!mediaSession.isActive()) { + return; + } + + if (DEBUG) { + if (getMetadataTitle() == null) { + Log.d(TAG, "N_getMetadataTitle: title == null"); + } + if (getMetadataArtist() == null) { + Log.d(TAG, "N_getMetadataArtist: artist == null"); + } + if (getMetadataDuration() <= 1) { + Log.d(TAG, "N_getMetadataDuration: duration <= 1; " + getMetadataDuration()); + } + } + + if (getMetadataTitle() == null || getMetadataArtist() == null || getMetadataDuration() <= 1 + || !getMetadataTitle().equals(title)) { + if (DEBUG) { + Log.d(TAG, "setMetadata: N_Metadata update: t: " + title + " a: " + artist + + " d: " + duration); + } + + mediaSession.setMetadata(new MediaMetadataCompat.Builder() + .putString(MediaMetadataCompat.METADATA_KEY_TITLE, title) + .putString(MediaMetadataCompat.METADATA_KEY_ARTIST, artist) + .putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration).build()); + } + } + public void setMetadata(final String title, final String artist, final Bitmap albumArt,