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 319c163e8..040070b5b 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -765,17 +765,15 @@ public final class Player implements PlaybackListener, Listener { + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + "], from = [" + from + "]"); } - currentThumbnail = bitmap; // there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too. - UIs.call(playerUi -> playerUi.onThumbnailLoaded(bitmap)); + onThumbnailLoaded(bitmap); } @Override public void onBitmapFailed(final Exception e, final Drawable errorDrawable) { Log.e(TAG, "Thumbnail - onBitmapFailed() called", e); - currentThumbnail = null; // there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too. - UIs.call(playerUi -> playerUi.onThumbnailLoaded(null)); + onThumbnailLoaded(null); } @Override @@ -798,7 +796,7 @@ public final class Player implements PlaybackListener, Listener { // Unset currentThumbnail, since it is now outdated. This ensures it is not used in media // session metadata while the new thumbnail is being loaded by Picasso. - currentThumbnail = null; + onThumbnailLoaded(null); if (isNullOrEmpty(url)) { return; } @@ -813,6 +811,16 @@ public final class Player implements PlaybackListener, Listener { // cancel the Picasso job associated with the player thumbnail, if any PicassoHelper.cancelTag(PICASSO_PLAYER_THUMBNAIL_TAG); } + + private void onThumbnailLoaded(@Nullable final Bitmap bitmap) { + // Avoid useless thumbnail updates, if the thumbnail has not actually changed. Based on the + // thumbnail loading code, this if would be skipped only when both bitmaps are `null`, since + // onThumbnailLoaded won't be called twice with the same nonnull bitmap by Picasso's target. + if (currentThumbnail != bitmap) { + currentThumbnail = bitmap; + UIs.call(playerUi -> playerUi.onThumbnailLoaded(bitmap)); + } + } //endregion