MediaLibraryService.MediaLibrarySession

Added in 1.0.0
Deprecated in 1.3.0

class MediaLibraryService.MediaLibrarySession : 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 functions

Unit
notifyChildrenChanged(
    parentId: String,
    itemCount: Int,
    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 subscribe.

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

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

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

Notifies controller about change in the search result.

Inherited functions

From java.io.Closeable
abstract Unit
From androidx.media2.session.MediaSession
Unit

Broadcasts a custom command to all connected controllers.

Unit
(Mutable)List<MediaSession.ControllerInfo!>

Returns the list of connected controller.

String

Gets the session ID

SessionPlayer

Gets the underlying SessionPlayer.

MediaSessionCompat.Token

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

SessionToken

Returns the SessionToken for creating MediaController.

ListenableFuture<SessionResult!>
sendCustomCommand(
    controller: MediaSession.ControllerInfo,
    command: SessionCommand,
    args: Bundle?
)

Sends a custom command to a specific controller.

Unit
setAllowedCommands(
    controller: MediaSession.ControllerInfo,
    commands: SessionCommandGroup
)

Sets the new allowed command group for the controller.

ListenableFuture<SessionResult!>

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

Unit

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

Public functions

notifyChildrenChanged

Added in 1.0.0
Deprecated in 1.3.0
fun notifyChildrenChanged(
    parentId: String,
    itemCount: Int,
    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 subscribe.

Parameters
parentId: String

non-empty parent id

itemCount: Int

number of children

params: MediaLibraryService.LibraryParams?

library params

notifyChildrenChanged

Added in 1.0.0
Deprecated in 1.3.0
fun notifyChildrenChanged(
    controller: MediaSession.ControllerInfo,
    parentId: String,
    itemCount: @IntRange(from = 0) Int,
    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 getChildren 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: @IntRange(from = 0) Int

number of children.

params: MediaLibraryService.LibraryParams?

library params

notifySearchResultChanged

Added in 1.0.0
Deprecated in 1.3.0
fun notifySearchResultChanged(
    controller: MediaSession.ControllerInfo,
    query: String,
    itemCount: @IntRange(from = 0) Int,
    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: @IntRange(from = 0) Int

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

params: MediaLibraryService.LibraryParams?

library params