Implement onSubscribe in session demo service

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
This commit is contained in:
bachinger 2022-05-23 11:23:30 +01:00 committed by Ian Baker
parent 07039a45b0
commit 08fc89a585

View File

@ -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 {