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

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.
This commit is contained in:
Stypox 2022-07-21 23:03:42 +02:00 committed by litetex
parent 3cc43e9fb9
commit f3a9b81b67
2 changed files with 16 additions and 5 deletions

View File

@ -748,11 +748,15 @@ public final class Player implements PlaybackListener, Listener {
//////////////////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////////////////*/
//region Thumbnail loading //region Thumbnail loading
private void initThumbnail(final String url) { private void loadCurrentThumbnail(final String url) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Thumbnail - initThumbnail() called with url = [" Log.d(TAG, "Thumbnail - loadCurrentThumbnail() called with url = ["
+ (url == null ? "null" : url) + "]"); + (url == null ? "null" : url) + "]");
} }
// 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;
if (isNullOrEmpty(url)) { if (isNullOrEmpty(url)) {
return; return;
} }
@ -762,8 +766,8 @@ public final class Player implements PlaybackListener, Listener {
@Override @Override
public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) { public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Thumbnail - onLoadingComplete() called with: url = [" + url Log.d(TAG, "Thumbnail - onBitmapLoaded() called with: url = [" + url
+ "], " + "loadedImage = [" + bitmap + " -> " + bitmap.getWidth() + "x" + "], " + "bitmap = [" + bitmap + " -> " + bitmap.getWidth() + "x"
+ bitmap.getHeight() + "], from = [" + from + "]"); + bitmap.getHeight() + "], from = [" + from + "]");
} }
@ -1727,7 +1731,7 @@ public final class Player implements PlaybackListener, Listener {
maybeAutoQueueNextStream(info); maybeAutoQueueNextStream(info);
initThumbnail(info.getThumbnailUrl()); loadCurrentThumbnail(info.getThumbnailUrl());
registerStreamViewed(); registerStreamViewed();
notifyMetadataUpdateToListeners(); notifyMetadataUpdateToListeners();

View File

@ -1,10 +1,12 @@
package org.schabi.newpipe.util; package org.schabi.newpipe.util;
import static org.schabi.newpipe.MainActivity.DEBUG;
import static org.schabi.newpipe.extractor.utils.Utils.isBlank; import static org.schabi.newpipe.extractor.utils.Utils.isBlank;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.util.Log;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -24,6 +26,7 @@ import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
public final class PicassoHelper { public final class PicassoHelper {
private static final String TAG = PicassoHelper.class.getSimpleName();
public static final String PLAYER_THUMBNAIL_TAG = "PICASSO_PLAYER_THUMBNAIL_TAG"; public static final String PLAYER_THUMBNAIL_TAG = "PICASSO_PLAYER_THUMBNAIL_TAG";
private static final String PLAYER_THUMBNAIL_TRANSFORMATION_KEY = private static final String PLAYER_THUMBNAIL_TRANSFORMATION_KEY =
"PICASSO_PLAYER_THUMBNAIL_TRANSFORMATION_KEY"; "PICASSO_PLAYER_THUMBNAIL_TRANSFORMATION_KEY";
@ -129,6 +132,10 @@ public final class PicassoHelper {
.transform(new Transformation() { .transform(new Transformation() {
@Override @Override
public Bitmap transform(final Bitmap source) { public Bitmap transform(final Bitmap source) {
if (DEBUG) {
Log.d(TAG, "Thumbnail - transform() called");
}
final float notificationThumbnailWidth = Math.min( final float notificationThumbnailWidth = Math.min(
context.getResources() context.getResources()
.getDimension(R.dimen.player_notification_thumbnail_width), .getDimension(R.dimen.player_notification_thumbnail_width),