Update media browsers when the list of local playlist changes

This commit is contained in:
Haggai Eran 2023-08-22 18:32:59 +03:00 committed by Siddhesh Naik
parent c916608c98
commit 0af4c34318
1 changed files with 17 additions and 0 deletions

View File

@ -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")