1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

Unify onThumbnailLoaded calls to ensure UIs always updated

This commit is contained in:
Stypox 2022-08-28 17:24:51 +02:00
parent e6391a860a
commit 7fbef35daa
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -765,17 +765,15 @@ public final class Player implements PlaybackListener, Listener {
+ " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + "], from = [" + " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + "], from = ["
+ from + "]"); + from + "]");
} }
currentThumbnail = bitmap;
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too. // 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 @Override
public void onBitmapFailed(final Exception e, final Drawable errorDrawable) { public void onBitmapFailed(final Exception e, final Drawable errorDrawable) {
Log.e(TAG, "Thumbnail - onBitmapFailed() called", e); 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. // 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 @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 // 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. // session metadata while the new thumbnail is being loaded by Picasso.
currentThumbnail = null; onThumbnailLoaded(null);
if (isNullOrEmpty(url)) { if (isNullOrEmpty(url)) {
return; return;
} }
@ -813,6 +811,16 @@ public final class Player implements PlaybackListener, Listener {
// cancel the Picasso job associated with the player thumbnail, if any // cancel the Picasso job associated with the player thumbnail, if any
PicassoHelper.cancelTag(PICASSO_PLAYER_THUMBNAIL_TAG); 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 //endregion