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
This commit is contained in:
parent
15eb7f3186
commit
6aebbc3109
1 changed files with 7 additions and 1 deletions
|
@ -275,6 +275,8 @@ public final class BackgroundPlayer extends Service {
|
||||||
protected class BasePlayerImpl extends BasePlayer {
|
protected class BasePlayerImpl extends BasePlayer {
|
||||||
|
|
||||||
@NonNull final private AudioPlaybackResolver resolver;
|
@NonNull final private AudioPlaybackResolver resolver;
|
||||||
|
private int cachedDuration;
|
||||||
|
private String cachedDurationString;
|
||||||
|
|
||||||
BasePlayerImpl(Context context) {
|
BasePlayerImpl(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -351,8 +353,12 @@ public final class BackgroundPlayer extends Service {
|
||||||
resetNotification();
|
resetNotification();
|
||||||
if(Build.VERSION.SDK_INT >= 26 /*Oreo*/) updateNotificationThumbnail();
|
if(Build.VERSION.SDK_INT >= 26 /*Oreo*/) updateNotificationThumbnail();
|
||||||
if (bigNotRemoteView != null) {
|
if (bigNotRemoteView != null) {
|
||||||
|
if(cachedDuration != duration) {
|
||||||
|
cachedDuration = duration;
|
||||||
|
cachedDurationString = getTimeString(duration);
|
||||||
|
}
|
||||||
bigNotRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false);
|
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) {
|
if (notRemoteView != null) {
|
||||||
notRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false);
|
notRemoteView.setProgressBar(R.id.notificationProgressBar, duration, currentProgress, false);
|
||||||
|
|
Loading…
Reference in a new issue