public final class

MediaLibraryService.MediaLibrarySession

extends MediaSession

 java.lang.Object

androidx.media3.session.MediaSession

↳androidx.media3.session.MediaLibraryService.MediaLibrarySession

Overview

An extended MediaSession for the MediaLibraryService. Build an instance with MediaLibraryService.MediaLibrarySession.Builder and return it from MediaSessionService.

Backward compatibility with legacy media browser APIs

A library session supports connection from both MediaBrowser and android.support.v4.media.MediaBrowserCompat, but the MediaSession.ControllerInfo may not be precise. Here are the details.

Summary when controller info isn't precise
SDK version MediaSession.ControllerInfo.getPackageName()
for legacy browser
MediaSession.ControllerInfo.getUid()
for legacy browser
SDK_INT < 21 Actual package name via Actual UID
21 <= SDK_INT < 28
for onConnect
and onGetLibraryRoot
Actual package name via Actual UID
21 <= SDK_INT < 28
for other callbacks
MediaSessionManager.RemoteUserInfo.LEGACY_CONTROLLER Negative value
28 <= SDK_INT Actual package name via Actual UID

Summary

Methods
public voidnotifyChildrenChanged(MediaSession.ControllerInfo browser, java.lang.String parentId, int itemCount, MediaLibraryService.LibraryParams params)

Notifies a browser that is subscribing to the change to a parent's children.

public voidnotifyChildrenChanged(java.lang.String parentId, int itemCount, MediaLibraryService.LibraryParams params)

Notifies all browsers that are subscribing to the parent of the change to its children regardless of the params given by MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSubscribe(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).

public voidnotifySearchResultChanged(MediaSession.ControllerInfo browser, java.lang.String query, int itemCount, MediaLibraryService.LibraryParams params)

Notifies a browser of a change to the search result.

from MediaSessionbroadcastCustomCommand, getConnectedControllers, getId, getPlayer, getSessionCompatToken, getToken, release, sendCustomCommand, setAvailableCommands, setCustomLayout, setPlayer
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public void notifyChildrenChanged(MediaSession.ControllerInfo browser, java.lang.String parentId, int itemCount, MediaLibraryService.LibraryParams params)

Notifies a browser that is subscribing to the change to a parent's children. If the browser isn't subscribing to the parent, nothing will happen.

This only tells the number of child media items. MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onGetChildren(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, int, int, MediaLibraryService.LibraryParams) will be called by the browser afterwards to get the list of media items.

Parameters:

browser: The browser to notify.
parentId: The non-empty id of the parent with changes to its children.
itemCount: The number of children.
params: The parameters given by MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSubscribe(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).

public void notifyChildrenChanged(java.lang.String parentId, int itemCount, MediaLibraryService.LibraryParams params)

Notifies all browsers that are subscribing to the parent of the change to its children regardless of the params given by MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSubscribe(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).

Parameters:

parentId: The non-empty id of the parent with changes to its children.
itemCount: The number of children.
params: The optional parameters.

public void notifySearchResultChanged(MediaSession.ControllerInfo browser, java.lang.String query, int itemCount, MediaLibraryService.LibraryParams params)

Notifies a browser of a change to the search result.

Parameters:

browser: The browser to notify.
query: The non-empty search query given by MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSearch(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).
itemCount: The number of items that have been found in the search.
params: The parameters given by MediaLibraryService.MediaLibrarySession.MediaLibrarySessionCallback.onSearch(MediaLibraryService.MediaLibrarySession, MediaSession.ControllerInfo, String, MediaLibraryService.LibraryParams).