Speeding up notification update

startForeground() is significantly slower than just notify()
This commit is contained in:
ByteHamster 2019-10-06 12:44:43 +02:00
parent b2d9455d6c
commit 6f809b47e6
1 changed files with 5 additions and 1 deletions

View File

@ -1184,6 +1184,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
private synchronized void setupNotification(final Playable playable) {
Log.d(TAG, "setupNotification");
if (notificationSetupThread != null) {
notificationSetupThread.interrupt();
}
@ -1200,6 +1201,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
notificationBuilder.setMetadata(playable, mediaSession.getSessionToken(), playerStatus, isCasting);
notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed());
Log.d(TAG, "setupNotification: startForeground" + playerStatus);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
startForegroundIfPlaying(playerStatus);
if (!notificationBuilder.isIconCached()) {
@ -1207,7 +1211,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Log.d(TAG, "Loading notification icon");
notificationBuilder.loadIcon();
if (!Thread.currentThread().isInterrupted()) {
startForegroundIfPlaying(playerStatus);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
});
notificationSetupThread.start();