Android 12 Developer Preview is here! Try it out, and give us your feedback!


class MediaLibrarySession : MediaSession
   ↳ androidx.media2.session.MediaSession
   ↳ androidx.media2.session.MediaLibraryService.MediaLibrarySession

Session for the MediaLibraryService. Build this object with Builder and return in MediaSessionService#onGetSession(ControllerInfo).

Backward compatibility with legacy media browser APIs

Media library session supports connection from both MediaBrowser and, but ControllerInfo may not be precise. Here are current limitations with details.
SDK version ControllerInfo#getPackageName()
for legacy browser
for legacy browser
SDK_VERSION < 21 Actual package name via Context#getPackageName() Actual UID
21 ≥ SDK_VERSION < 28,
MediaLibrarySessionCallback#onConnect and
Actual package name via Context#getPackageName() Actual UID
21 ≥ SDK_VERSION < 28, for other callbacks RemoteUserInfo#LEGACY_CONTROLLER Negative value
28 ≥ SDK_VERSION Actual package name via Context#getPackageName() Actual UID


Nested classes

Builder for MediaLibrarySession.

Callback for the MediaLibrarySession.

Public methods
notifyChildrenChanged(@NonNull controller: MediaSession.ControllerInfo, @NonNull parentId: String, @IntRange(0) itemCount: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Notifies the controller of the change in a parent's children.

notifyChildrenChanged(@NonNull parentId: String, itemCount: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Notifies all controllers that subscribed to the parent about change in the parent's children, regardless of the library params supplied by MediaBrowser#subscribe(String, LibraryParams).

notifySearchResultChanged(@NonNull controller: MediaSession.ControllerInfo, @NonNull query: String, @IntRange(0) itemCount: Int, @Nullable params: MediaLibraryService.LibraryParams?)

Notifies controller about change in the search result.

Inherited functions