diff --git a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java index 7a383e096..3593155ef 100644 --- a/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java +++ b/app/src/main/java/org/schabi/newpipe/player/mediabrowser/MediaBrowserConnector.java @@ -70,6 +70,8 @@ public class MediaBrowserConnector implements MediaSessionConnector.PlaybackPrep sessionConnector.setMetadataDeduplicationEnabled(true); sessionConnector.setPlaybackPreparer(this); playerService.setSessionToken(mediaSession.getSessionToken()); + + setupBookmarksNotifications(); } @NonNull @@ -79,6 +81,7 @@ public class MediaBrowserConnector implements MediaSessionConnector.PlaybackPrep public void release() { disposePrepareOrPlayCommands(); + disposeBookmarksNotifications(); mediaSession.release(); } @@ -228,6 +231,20 @@ public class MediaBrowserConnector implements MediaSessionConnector.PlaybackPrep return localPlaylistManager; } + @Nullable Disposable bookmarksNotificationsDisposable; + + private void setupBookmarksNotifications() { + bookmarksNotificationsDisposable = getPlaylistManager().getPlaylists().subscribe( + playlistMetadataEntries -> playerService.notifyChildrenChanged(ID_BOOKMARKS)); + } + + private void disposeBookmarksNotifications() { + if (bookmarksNotificationsDisposable != null) { + bookmarksNotificationsDisposable.dispose(); + bookmarksNotificationsDisposable = null; + } + } + // Suppress Sonar warning replace list collection by Stream.toList call, as this method is only // available in Android API 34 and not currently available with desugaring @SuppressWarnings("squid:S6204")