Skip to content

Commit 25f40a6

Browse files
committed
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 80df363 commit 25f40a6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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,11 +1,13 @@
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;
89
import android.graphics.drawable.Drawable;
10+
import android.util.Log;
911

1012
import androidx.annotation.Nullable;
1113

@@ -27,6 +29,7 @@
2729
import okhttp3.OkHttpClient;
2830

2931
public final class PicassoHelper {
32+
private static final String TAG = PicassoHelper.class.getSimpleName();
3033
public static final String PLAYER_THUMBNAIL_TAG = "PICASSO_PLAYER_THUMBNAIL_TAG";
3134
private static final String PLAYER_THUMBNAIL_TRANSFORMATION_KEY =
3235
"PICASSO_PLAYER_THUMBNAIL_TRANSFORMATION_KEY";
@@ -128,6 +131,10 @@ public static RequestCreator loadScaledDownThumbnail(final Context context, fina
128131
.transform(new Transformation() {
129132
@Override
130133
public Bitmap transform(final Bitmap source) {
134+
if (DEBUG) {
135+
Log.d(TAG, "Thumbnail - transform() called");
136+
}
137+
131138
final float notificationThumbnailWidth = Math.min(
132139
context.getResources()
133140
.getDimension(R.dimen.player_notification_thumbnail_width),

0 commit comments

Comments
 (0)