MediaLibraryService.MediaLibrarySession

Added in 1.0.0
Deprecated in 1.3.0

public final class MediaLibraryService.MediaLibrarySession extends MediaSession


Session for the MediaLibraryService. Build this object with Builder and return in onGetSession.

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 for legacy browser for legacy browser
SDK_VERSION<21 Actual package name via getPackageName Actual UID
21 ≥ SDK_VERSION<28,MediaLibrarySessionCallback#onConnect andMediaLibrarySessionCallback#onGetLibraryRoot Actual package name via getPackageName Actual UID
21 ≥ SDK_VERSION<28, for other callbacks LEGACY_CONTROLLER Negative value
28 ≥ SDK_VERSION Actual package name via getPackageName Actual UID

Summary

Nested types

This class is deprecated.

androidx.media2 is deprecated.

This class is deprecated.

androidx.media2 is deprecated.

Public methods

void
notifyChildrenChanged(
    @NonNull String parentId,
    int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

Notifies all controllers that subscribed to the parent about change in the parent's children, regardless of the library params supplied by subscribe.

void
notifyChildrenChanged(
    @NonNull MediaSession.ControllerInfo controller,
    @NonNull String parentId,
    @IntRange(from = 0) int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

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

void
notifySearchResultChanged(
    @NonNull MediaSession.ControllerInfo controller,
    @NonNull String query,
    @IntRange(from = 0) int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

Notifies controller about change in the search result.

Inherited methods

From java.io.Closeable
abstract void
From androidx.media2.session.MediaSession
void
broadcastCustomCommand(
    @NonNull SessionCommand command,
    @Nullable Bundle args
)

Broadcasts a custom command to all connected controllers.

void
@NonNull List<MediaSession.ControllerInfo>

Returns the list of connected controller.

@NonNull String

Gets the session ID

@NonNull SessionPlayer

Gets the underlying SessionPlayer.

@NonNull MediaSessionCompat.Token

Gets the MediaSessionCompat.Token for the MediaSessionCompat created internally by this session.

@NonNull SessionToken

Returns the SessionToken for creating MediaController.

@NonNull ListenableFuture<SessionResult>
sendCustomCommand(
    @NonNull MediaSession.ControllerInfo controller,
    @NonNull SessionCommand command,
    @Nullable Bundle args
)

Sends a custom command to a specific controller.

void

Sets the new allowed command group for the controller.

@NonNull ListenableFuture<SessionResult>

Sets ordered list of CommandButton for controllers to build UI with it.

void

Updates the underlying SessionPlayer for this session to dispatch incoming event to.

Public methods

notifyChildrenChanged

Added in 1.0.0
Deprecated in 1.3.0
public void notifyChildrenChanged(
    @NonNull String parentId,
    int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

Notifies all controllers that subscribed to the parent about change in the parent's children, regardless of the library params supplied by subscribe.

Parameters
@NonNull String parentId

non-empty parent id

int itemCount

number of children

@Nullable MediaLibraryService.LibraryParams params

library params

notifyChildrenChanged

Added in 1.0.0
Deprecated in 1.3.0
public void notifyChildrenChanged(
    @NonNull MediaSession.ControllerInfo controller,
    @NonNull String parentId,
    @IntRange(from = 0) int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

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 getChildren to get the list of children.

Parameters
@NonNull MediaSession.ControllerInfo controller

controller to notify

@NonNull String parentId

non-empty parent id with changes in its children

@IntRange(from = 0) int itemCount

number of children.

@Nullable MediaLibraryService.LibraryParams params

library params

notifySearchResultChanged

Added in 1.0.0
Deprecated in 1.3.0
public void notifySearchResultChanged(
    @NonNull MediaSession.ControllerInfo controller,
    @NonNull String query,
    @IntRange(from = 0) int itemCount,
    @Nullable MediaLibraryService.LibraryParams params
)

Notifies controller about change in the search result.

Parameters
@NonNull MediaSession.ControllerInfo controller

controller to notify

@NonNull String query

previously sent non-empty search query from the controller.

@IntRange(from = 0) int itemCount

the number of items that have been found in the search.

@Nullable MediaLibraryService.LibraryParams params

library params