1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-26 04:52:29 +01:00

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
This commit is contained in:
Stypox 2020-09-10 18:47:22 +02:00
parent 5846fbabce
commit bccfe500b3
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 14 additions and 6 deletions

View File

@ -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(),

View File

@ -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);