Package com.castlabs.sdk.mediasession

# Interface MediaSessionBuilder.Listener

Enclosing class:
  `MediaSessionBuilder`

public static interface MediaSessionBuilder.Listener
A listener to provide media session events.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `default void`
  `onAddMediaItems(androidx.media3.session.MediaSession mediaSession, androidx.media3.session.MediaSession.ControllerInfo controller, List<androidx.media3.common.MediaItem> mediaItems)`
  Called when media items are added.
  `default void`
  `onConnect(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller)`
  Called when a controller is about to connect the session.
  `default void`
  `onCustomCommand(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller, androidx.media3.session.SessionCommand customCommand, Bundle args)`
  Called when a custom command is received.
  `default void`
  `onDisconnected(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller)`
  Called when a controller is disconnected.
  `default void`
  `onGetChildren(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String parentId, int page, int pageSize, androidx.media3.session.MediaLibraryService.LibraryParams params)`
  Called to get children of the given parent ID.
  `default void`
  `onGetItem(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String mediaId)`
  Called to get an item with the given media ID.
  `default void`
  `onGetLibraryRoot(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, androidx.media3.session.MediaLibraryService.LibraryParams params)`
  Called to get the library root.
  `default void`
  `onGetSearchResult(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String query, int page, int pageSize, androidx.media3.session.MediaLibraryService.LibraryParams params)`
  Called to get search results.
  `default void`
  `onMediaButtonEvent(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controllerInfo, Intent intent)`
  Called when a media button event is received.
  `default void`
  `onPlaybackResumption(androidx.media3.session.MediaSession mediaSession, androidx.media3.session.MediaSession.ControllerInfo controller)`
  Called when playback resumption is requested.
  `default void`
  `onPlayerInteractionFinished(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controllerInfo, androidx.media3.common.Player.Commands playerCommands)`
  Called when player interaction is finished.
  `default void`
  `onPostConnect(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller)`
  Called after a connection is established.
  `default void`
  `onSearch(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String query, androidx.media3.session.MediaLibraryService.LibraryParams params)`
  Called when a search is performed.
  `default void`
  `onSetMediaItems(androidx.media3.session.MediaSession mediaSession, androidx.media3.session.MediaSession.ControllerInfo controller, List<androidx.media3.common.MediaItem> mediaItems, int startIndex, long startPositionMs)`
  Called when media items are set.
  `default void`
  `onSetRating(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller, androidx.media3.common.Rating rating)`
  Called when a rating is set for the current media item.
  `default void`
  `onSetRating(androidx.media3.session.MediaSession session, androidx.media3.session.MediaSession.ControllerInfo controller, String mediaId, androidx.media3.common.Rating rating)`
  Called when a rating is set for a specific media item.
  `default void`
  `onSubscribe(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String parentId, androidx.media3.session.MediaLibraryService.LibraryParams params)`
  Called when a subscription to a parent ID is added.
  `default void`
  `onUnsubscribe(androidx.media3.session.MediaLibraryService.MediaLibrarySession session, androidx.media3.session.MediaSession.ControllerInfo browser, String parentId)`
  Called when a subscription to a parent ID is removed.

- ## Method Details

  - ### onConnect

    default void onConnect(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller)
    Called when a controller is about to connect the session.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info

  - ### onDisconnected

    default void onDisconnected(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller)
    Called when a controller is disconnected.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info

  - ### onCustomCommand

    default void onCustomCommand(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller, @NonNull androidx.media3.session.SessionCommand customCommand, @NonNull Bundle args)
    Called when a custom command is received.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info
      `customCommand` - The custom command
      `args` - A Bundle for additional arguments. May be empty

  - ### onGetChildren

    default void onGetChildren(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String parentId, int page, int pageSize, @Nullable androidx.media3.session.MediaLibraryService.LibraryParams params)
    Called to get children of the given parent ID.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `parentId` - The parent ID
      `page` - The page number
      `pageSize` - The page size
      `params` - Optional parameters

  - ### onGetItem

    default void onGetItem(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String mediaId)
    Called to get an item with the given media ID.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `mediaId` - The media ID

  - ### onGetLibraryRoot

    default void onGetLibraryRoot(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @Nullable androidx.media3.session.MediaLibraryService.LibraryParams params)
    Called to get the library root.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `params` - Optional parameters

  - ### onGetSearchResult

    default void onGetSearchResult(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String query, int page, int pageSize, @Nullable androidx.media3.session.MediaLibraryService.LibraryParams params)
    Called to get search results.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `query` - The search query
      `page` - The page number
      `pageSize` - The page size
      `params` - Optional parameters

  - ### onSearch

    default void onSearch(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String query, @Nullable androidx.media3.session.MediaLibraryService.LibraryParams params)
    Called when a search is performed.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `query` - The search query
      `params` - Optional parameters

  - ### onSubscribe

    default void onSubscribe(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String parentId, @Nullable androidx.media3.session.MediaLibraryService.LibraryParams params)
    Called when a subscription to a parent ID is added.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `parentId` - The parent ID
      `params` - Optional parameters

  - ### onUnsubscribe

    default void onUnsubscribe(@NonNull androidx.media3.session.MediaLibraryService.MediaLibrarySession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo browser, @NonNull String parentId)
    Called when a subscription to a parent ID is removed.
    Parameters:
      `session` - The session for this event
      `browser` - The controller info
      `parentId` - The parent ID

  - ### onAddMediaItems

    default void onAddMediaItems(@NonNull androidx.media3.session.MediaSession mediaSession, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller, @NonNull List<androidx.media3.common.MediaItem> mediaItems)
    Called when media items are added.
    Parameters:
      `mediaSession` - The session for this event
      `controller` - The controller info
      `mediaItems` - The media items to add

  - ### onMediaButtonEvent

    default void onMediaButtonEvent(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controllerInfo, @NonNull Intent intent)
    Called when a media button event is received.
    Parameters:
      `session` - The session for this event
      `controllerInfo` - The controller info
      `intent` - The media button intent

  - ### onPlaybackResumption

    default void onPlaybackResumption(@NonNull androidx.media3.session.MediaSession mediaSession, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller)
    Called when playback resumption is requested.
    Parameters:
      `mediaSession` - The session for this event
      `controller` - The controller info

  - ### onPlayerInteractionFinished

    default void onPlayerInteractionFinished(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controllerInfo, @NonNull androidx.media3.common.Player.Commands playerCommands)
    Called when player interaction is finished.
    Parameters:
      `session` - The session for this event
      `controllerInfo` - The controller info
      `playerCommands` - The player commands

  - ### onPostConnect

    default void onPostConnect(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller)
    Called after a connection is established.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info

  - ### onSetMediaItems

    default void onSetMediaItems(@NonNull androidx.media3.session.MediaSession mediaSession, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller, @NonNull List<androidx.media3.common.MediaItem> mediaItems, int startIndex, long startPositionMs)
    Called when media items are set.
    Parameters:
      `mediaSession` - The session for this event
      `controller` - The controller info
      `mediaItems` - The media items to set
      `startIndex` - The start index
      `startPositionMs` - The start position in milliseconds

  - ### onSetRating

    default void onSetRating(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller, @NonNull String mediaId, @NonNull androidx.media3.common.Rating rating)
    Called when a rating is set for a specific media item.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info
      `mediaId` - The media ID
      `rating` - The rating

  - ### onSetRating

    default void onSetRating(@NonNull androidx.media3.session.MediaSession session, @NonNull androidx.media3.session.MediaSession.ControllerInfo controller, @NonNull androidx.media3.common.Rating rating)
    Called when a rating is set for the current media item.
    Parameters:
      `session` - The session for this event
      `controller` - The controller info
      `rating` - The rating