Skip to content

Commit f3a9b81

Browse files
Stypoxlitetex
authored andcommitted
Fix sometimes seeing outdated thumbnail in notification
Before the thumbnail finishes loading for the new video the player is now playing, the old thumbnail was being used, leading to wrong thumbnails set in the media session and the notification.
1 parent 3cc43e9 commit f3a9b81

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,15 @@ private void unregisterBroadcastReceiver() {
748748
//////////////////////////////////////////////////////////////////////////*/
749749
//region Thumbnail loading
750750

751-
private void initThumbnail(final String url) {
751+
private void loadCurrentThumbnail(final String url) {
752752
if (DEBUG) {
753-
Log.d(TAG, "Thumbnail - initThumbnail() called with url = ["
753+
Log.d(TAG, "Thumbnail - loadCurrentThumbnail() called with url = ["
754754
+ (url == null ? "null" : url) + "]");
755755
}
756+
757+
// Unset currentThumbnail, since it is now outdated. This ensures it is not used in media
758+
// session metadata while the new thumbnail is being loaded by Picasso.
759+
currentThumbnail = null;
756760
if (isNullOrEmpty(url)) {
757761
return;
758762
}
@@ -762,8 +766,8 @@ private void initThumbnail(final String url) {
762766
@Override
763767
public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) {
764768
if (DEBUG) {
765-
Log.d(TAG, "Thumbnail - onLoadingComplete() called with: url = [" + url
766-
+ "], " + "loadedImage = [" + bitmap + " -> " + bitmap.getWidth() + "x"
769+
Log.d(TAG, "Thumbnail - onBitmapLoaded() called with: url = [" + url
770+
+ "], " + "bitmap = [" + bitmap + " -> " + bitmap.getWidth() + "x"
767771
+ bitmap.getHeight() + "], from = [" + from + "]");
768772
}
769773

@@ -1727,7 +1731,7 @@ private void updateMetadataWith(@NonNull final StreamInfo info) {
17271731

17281732
maybeAutoQueueNextStream(info);
17291733

1730-
initThumbnail(info.getThumbnailUrl());
1734+
loadCurrentThumbnail(info.getThumbnailUrl());
17311735
registerStreamViewed();
17321736

17331737
notifyMetadataUpdateToListeners();

app/src/main/java/org/schabi/newpipe/util/PicassoHelper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.schabi.newpipe.util;
22

3+
import static org.schabi.newpipe.MainActivity.DEBUG;
34
import static org.schabi.newpipe.extractor.utils.Utils.isBlank;
45

56
import android.annotation.SuppressLint;
67
import android.content.Context;
78
import android.graphics.Bitmap;
9+
import android.util.Log;
810

911
import androidx.annotation.Nullable;
1012

@@ -24,6 +26,7 @@
2426
import okhttp3.OkHttpClient;
2527

2628
public final class PicassoHelper {
29+
private static final String TAG = PicassoHelper.class.getSimpleName();
2730
public static final String PLAYER_THUMBNAIL_TAG = "PICASSO_PLAYER_THUMBNAIL_TAG";
2831
private static final String PLAYER_THUMBNAIL_TRANSFORMATION_KEY =
2932
"PICASSO_PLAYER_THUMBNAIL_TRANSFORMATION_KEY";
@@ -129,6 +132,10 @@ public static RequestCreator loadScaledDownThumbnail(final Context context, fina
129132
.transform(new Transformation() {
130133
@Override
131134
public Bitmap transform(final Bitmap source) {
135+
if (DEBUG) {
136+
Log.d(TAG, "Thumbnail - transform() called");
137+
}
138+
132139
final float notificationThumbnailWidth = Math.min(
133140
context.getResources()
134141
.getDimension(R.dimen.player_notification_thumbnail_width),

0 commit comments

Comments
 (0)