Skip to content

Commit

Permalink
Update media browsers when the list of local playlist changes
Browse files Browse the repository at this point in the history
  • Loading branch information
haggaie committed May 29, 2024
1 parent c4d5c3c commit 4a0bf04
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public MediaBrowserConnector(@NonNull final PlayerService playerService) {
sessionConnector.setMetadataDeduplicationEnabled(true);
sessionConnector.setPlaybackPreparer(this);
playerService.setSessionToken(mediaSession.getSessionToken());

setupBookmarksNotifications();
}

@NonNull
Expand All @@ -79,6 +81,7 @@ public MediaSessionConnector getSessionConnector() {

public void release() {
disposePrepareOrPlayCommands();
disposeBookmarksNotifications();
mediaSession.release();
}

Expand Down Expand Up @@ -228,6 +231,20 @@ private LocalPlaylistManager getPlaylistManager() {
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")
Expand Down

0 comments on commit 4a0bf04

Please sign in to comment.