limit amount of notification thumbnail updates
limits amount of calls to updateNotificationThumbnail in background player
This commit is contained in:
parent
7f0a9904ff
commit
ee65e89230
|
@ -95,6 +95,9 @@ public final class BackgroundPlayer extends Service {
|
||||||
|
|
||||||
private boolean shouldUpdateOnProgress;
|
private boolean shouldUpdateOnProgress;
|
||||||
|
|
||||||
|
private static final int NOTIFICATION_UPDATES_BEFORE_RESET = 60;
|
||||||
|
private int timesNotificationUpdated;
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
// Service's LifeCycle
|
// Service's LifeCycle
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
@ -180,6 +183,7 @@ public final class BackgroundPlayer extends Service {
|
||||||
|
|
||||||
private void resetNotification() {
|
private void resetNotification() {
|
||||||
notBuilder = createNotification();
|
notBuilder = createNotification();
|
||||||
|
timesNotificationUpdated = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NotificationCompat.Builder createNotification() {
|
private NotificationCompat.Builder createNotification() {
|
||||||
|
@ -252,6 +256,7 @@ public final class BackgroundPlayer extends Service {
|
||||||
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
|
if (bigNotRemoteView != null) bigNotRemoteView.setImageViewResource(R.id.notificationPlayPause, drawableId);
|
||||||
}
|
}
|
||||||
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
|
notificationManager.notify(NOTIFICATION_ID, notBuilder.build());
|
||||||
|
timesNotificationUpdated++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -351,8 +356,10 @@ public final class BackgroundPlayer extends Service {
|
||||||
updateProgress(currentProgress, duration, bufferPercent);
|
updateProgress(currentProgress, duration, bufferPercent);
|
||||||
|
|
||||||
if (!shouldUpdateOnProgress) return;
|
if (!shouldUpdateOnProgress) return;
|
||||||
resetNotification();
|
if (timesNotificationUpdated > NOTIFICATION_UPDATES_BEFORE_RESET) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail();
|
resetNotification();
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O /*Oreo*/) updateNotificationThumbnail();
|
||||||
|
}
|
||||||
if (bigNotRemoteView != null) {
|
if (bigNotRemoteView != null) {
|
||||||
if(cachedDuration != duration) {
|
if(cachedDuration != duration) {
|
||||||
cachedDuration = duration;
|
cachedDuration = duration;
|
||||||
|
|
Loading…
Reference in New Issue