Class MediaSessionConnector

    • Field Detail

      • ACTION_SET_PLAYBACK_SPEED

        public static final long ACTION_SET_PLAYBACK_SPEED
        Indicates this session supports the set playback speed command.
        See Also:
        Constant Field Values
      • DEFAULT_PLAYBACK_ACTIONS

        public static final long DEFAULT_PLAYBACK_ACTIONS
        The default playback actions.
        See Also:
        Constant Field Values
      • EXTRAS_SPEED

        public static final String EXTRAS_SPEED
        The name of the PlaybackStateCompat float extra with the value of Player.getPlaybackParameters().speed.
        See Also:
        Constant Field Values
      • mediaSession

        public final android.support.v4.media.session.MediaSessionCompat mediaSession
        The wrapped MediaSessionCompat.
    • Constructor Detail

      • MediaSessionConnector

        public MediaSessionConnector​(android.support.v4.media.session.MediaSessionCompat mediaSession)
        Creates an instance.
        Parameters:
        mediaSession - The MediaSessionCompat to connect to.
    • Method Detail

      • setPlayer

        public void setPlayer​(@Nullable
                              Player player)
        Sets the player to be connected to the media session. Must be called on the same thread that is used to access the player.
        Parameters:
        player - The player to be connected to the MediaSession, or null to disconnect the current player.
      • setEnabledPlaybackActions

        public void setEnabledPlaybackActions​(long enabledPlaybackActions)
        Sets the enabled playback actions.
        Parameters:
        enabledPlaybackActions - The enabled playback actions.
      • setCustomErrorMessage

        public void setCustomErrorMessage​(@Nullable
                                          CharSequence message)
        Sets a custom error on the session.

        This sets the error code via PlaybackStateCompat.Builder.setErrorMessage(int, CharSequence). By default, the error code will be set to PlaybackStateCompat.ERROR_CODE_APP_ERROR.

        Parameters:
        message - The error string to report or null to clear the error.
      • setCustomErrorMessage

        public void setCustomErrorMessage​(@Nullable
                                          CharSequence message,
                                          int code)
        Sets a custom error on the session.
        Parameters:
        message - The error string to report or null to clear the error.
        code - The error code to report. Ignored when message is null.
      • setCustomErrorMessage

        public void setCustomErrorMessage​(@Nullable
                                          CharSequence message,
                                          int code,
                                          @Nullable
                                          Bundle extras)
        Sets a custom error on the session.
        Parameters:
        message - The error string to report or null to clear the error.
        code - The error code to report. Ignored when message is null.
        extras - Extras to include in reported PlaybackStateCompat.
      • setMediaMetadataProvider

        public void setMediaMetadataProvider​(@Nullable
                                             MediaSessionConnector.MediaMetadataProvider mediaMetadataProvider)
        Sets a provider of metadata to be published to the media session. Pass null if no metadata should be published.
        Parameters:
        mediaMetadataProvider - The provider of metadata to publish, or null if no metadata should be published.
      • invalidateMediaSessionMetadata

        public final void invalidateMediaSessionMetadata()
        Updates the metadata of the media session.

        Apps normally only need to call this method when the backing data for a given media item has changed and the metadata should be updated immediately.

        The MediaMetadataCompat which is published to the session is obtained by calling MediaSessionConnector.MediaMetadataProvider.getMetadata(Player).

      • invalidateMediaSessionPlaybackState

        public final void invalidateMediaSessionPlaybackState()
        Updates the playback state of the media session.

        Apps normally only need to call this method when the custom actions provided by a MediaSessionConnector.CustomActionProvider changed and the playback state needs to be updated immediately.

      • invalidateMediaSessionQueue

        public final void invalidateMediaSessionQueue()
        Updates the queue of the media session by calling MediaSessionConnector.QueueNavigator.onTimelineChanged(Player).

        Apps normally only need to call this method when the backing data for a given queue item has changed and the queue should be updated immediately.

      • registerCustomCommandReceiver

        public void registerCustomCommandReceiver​(@Nullable
                                                  MediaSessionConnector.CommandReceiver commandReceiver)
        Registers a custom command receiver for responding to commands delivered via MediaSessionCompat.Callback.onCommand(String, Bundle, ResultReceiver).

        Commands are only dispatched to this receiver when a player is connected.

        Parameters:
        commandReceiver - The command receiver to register.
      • unregisterCustomCommandReceiver

        public void unregisterCustomCommandReceiver​(@Nullable
                                                    MediaSessionConnector.CommandReceiver commandReceiver)
        Unregisters a previously registered custom command receiver.
        Parameters:
        commandReceiver - The command receiver to unregister.