Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

MediaLibrarySession

class MediaLibrarySession : MediaSession
kotlin.Any
   ↳ 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 android.support.v4.media.MediaBrowserCompat, but ControllerInfo may not be precise. Here are current limitations with details.
SDK version ControllerInfo#getPackageName()
for legacy browser
ControllerInfo#getUid()
for legacy browser
SDK_VERSION < 21 Actual package name via Context#getPackageName() Actual UID
21 ≥ SDK_VERSION < 28,
MediaLibrarySessionCallback#onConnect and
MediaLibrarySessionCallback#onGetLibraryRoot
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

Summary

Nested classes

Builder for MediaLibrarySession.

Callback for the MediaLibrarySession.

Public methods
Unit
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.

Unit
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).

Unit
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

Public methods

notifyChildrenChanged

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

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

If the controller hasn't subscribed to the parent, the API will do nothing.

Controllers will use MediaBrowser#getChildren(String, int, int, LibraryParams) to get the list of children.

Parameters
controller MediaSession.ControllerInfo: controller to notify
parentId String: non-empty parent id with changes in its children
itemCount Int: number of children.
params MediaLibraryService.LibraryParams?: library params

notifyChildrenChanged

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

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).

Parameters
parentId String: non-empty parent id
itemCount Int: number of children
params MediaLibraryService.LibraryParams?: library params

notifySearchResultChanged

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

Notifies controller about change in the search result.

Parameters
controller MediaSession.ControllerInfo: controller to notify
query String: previously sent non-empty search query from the controller.
itemCount Int: the number of items that have been found in the search.
params MediaLibraryService.LibraryParams?: library params