From bccfe500b39de8416f1deac9cc4a9468d8bf01cd Mon Sep 17 00:00:00 2001 From: Stypox Date: Thu, 10 Sep 2020 18:47:22 +0200 Subject: [PATCH] Fix seekbar invisible or not updating Have the notification recreate only when strictly necessary, and recreate it if there was a timeline change, fixing the seekbar not updating at all sometimes --- .../org/schabi/newpipe/player/NotificationUtil.java | 12 ++++++------ .../org/schabi/newpipe/player/VideoPlayerImpl.java | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java index e01b0ec49..b0bfcb6e1 100644 --- a/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java +++ b/app/src/main/java/org/schabi/newpipe/player/NotificationUtil.java @@ -78,10 +78,7 @@ public final class NotificationUtil { */ synchronized void createNotificationIfNeededAndUpdate(final VideoPlayerImpl player, final boolean forceRecreate) { - if (notificationBuilder == null || forceRecreate) { - if (DEBUG) { - Log.d(TAG, "N_ createNotificationIfNeededAndUpdate(true)"); - } + if (forceRecreate || notificationBuilder == null) { notificationBuilder = createNotification(player); } updateNotification(player); @@ -89,6 +86,9 @@ public final class NotificationUtil { private synchronized NotificationCompat.Builder createNotification( final VideoPlayerImpl player) { + if (DEBUG) { + Log.d(TAG, "createNotification()"); + } notificationManager = (NotificationManager) player.context.getSystemService(NOTIFICATION_SERVICE); final NotificationCompat.Builder builder = new NotificationCompat.Builder(player.context, @@ -132,7 +132,7 @@ public final class NotificationUtil { */ private synchronized void updateNotification(final VideoPlayerImpl player) { if (DEBUG) { - Log.d(TAG, "N_ updateNotification()"); + Log.d(TAG, "updateNotification()"); } if (notificationBuilder == null) { @@ -158,7 +158,7 @@ public final class NotificationUtil { void createNotificationAndStartForeground(final VideoPlayerImpl player, final Service service) { - createNotificationIfNeededAndUpdate(player, true); + createNotificationIfNeededAndUpdate(player, false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { service.startForeground(NOTIFICATION_ID, notificationBuilder.build(), diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 7e02549f1..f30330e4d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -66,6 +66,7 @@ import androidx.recyclerview.widget.RecyclerView; import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; +import com.google.android.exoplayer2.Timeline; import com.google.android.exoplayer2.source.MediaSource; import com.google.android.exoplayer2.text.CaptionStyleCompat; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; @@ -604,6 +605,13 @@ public class VideoPlayerImpl extends VideoPlayer } } + @Override + public void onTimelineChanged(final Timeline timeline, final int reason) { + super.onTimelineChanged(timeline, reason); + // force recreate notification to ensure seek bar is shown when preparation finishes + NotificationUtil.getInstance().createNotificationIfNeededAndUpdate(this, true); + } + protected void onMetadataChanged(@NonNull final MediaSourceTag tag) { super.onMetadataChanged(tag);