Skip to content

Commit

Permalink
Implement onSubscribe in session demo service
Browse files Browse the repository at this point in the history
Immediately notify a subscribing client about the availability of child items of
a parent ID to make the client load the children.

PiperOrigin-RevId: 450396690
  • Loading branch information
marcbaechinger authored and icbaker committed May 24, 2022
1 parent 07039a4 commit 08fc89a
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ class PlaybackService : MediaLibraryService() {
return SessionResult.RESULT_ERROR_NOT_SUPPORTED
}
}

override fun onSubscribe(
session: MediaLibrarySession,
browser: MediaSession.ControllerInfo,
parentId: String,
params: LibraryParams?
): ListenableFuture<LibraryResult<Void>> {
val children =
MediaItemTree.getChildren(parentId)
?: return Futures.immediateFuture(
LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE)
)
session.notifyChildrenChanged(browser, parentId, children.size, params)
return Futures.immediateFuture(LibraryResult.ofVoid())
}
}

private class CustomMediaItemFiller : MediaSession.MediaItemFiller {
Expand Down

0 comments on commit 08fc89a

Please sign in to comment.