From 6aebbc31096153a5f351ca802dd1510fe5a35d08 Mon Sep 17 00:00:00 2001 From: Redirion Date: Mon, 4 Mar 2019 10:24:08 +0100 Subject: [PATCH 1/2] Cache duration String to improve performance In VideoPlayer the Duration String is cached effectively by setting it to the playbackSeekBar. As the playbackSeekBar doesn't exist in BackgroundPlayer, using two addition variables will reduce performance impact of notification updates by almost 50% and thus perform similar to VideoPlayer. This addresses issue #2170 --- .../java/org/schabi/newpipe/player/BackgroundPlayer.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 94b401f09..83ac85b06 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -275,6 +275,8 @@ public final class BackgroundPlayer extends Service { protected class BasePlayerImpl extends BasePlayer { @NonNull final private AudioPlaybackResolver resolver; + private int cachedDuration; + private String cachedDurationString; BasePlayerImpl(Context context) { super(context); @@ -351,8 +353,12 @@ public final class BackgroundPlayer extends Service { resetNotification(); if(Build.VERSION.SDK_INT >= 26 /*Oreo*/) updateNotificationThumbnail(); if (bigNotRemoteView != null) { + if(cachedDuration != duration) { + cachedDuration = duration; + cachedDurationString = getTimeString(duration); + } bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false); - bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + getTimeString(duration)); + bigNotRemoteView.setTextViewText(R.id.notificationTime, getTimeString(currentProgress) + " / " + cachedDurationString); } if (notRemoteView != null) { notRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false); From 31c4ed7d0e22c4a441b033f86c572822506e4702 Mon Sep 17 00:00:00 2001 From: Tobias Groza Date: Tue, 5 Mar 2019 20:57:05 +0100 Subject: [PATCH 2/2] Update app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java Co-Authored-By: Redirion --- .../main/java/org/schabi/newpipe/player/BackgroundPlayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java index 83ac85b06..3989581fd 100644 --- a/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/BackgroundPlayer.java @@ -351,7 +351,7 @@ public final class BackgroundPlayer extends Service { if (!shouldUpdateOnProgress) return; resetNotification(); - if(Build.VERSION.SDK_INT >= 26 /*Oreo*/) updateNotificationThumbnail(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail(); if (bigNotRemoteView != null) { if(cachedDuration != duration) { cachedDuration = duration;