Class MediaSessionConnector
- java.lang.Object
-
- com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector
-
@Deprecated public final class MediaSessionConnector extends Object
Deprecated.com.google.android.exoplayer2 is deprecated. Please migrate to androidx.media3 (which contains the same ExoPlayer code). See the migration guide for more details, including a script to help with the migration.Connects aMediaSessionCompatto aPlayer.This connector does not call
MediaSessionCompat.setActive(boolean), and so application code is responsible for making the session active when desired. A session must be active for transport controls to be displayed (e.g. on the lock screen) and for it to receive media button events.The connector listens for actions sent by the media session's controller and implements these actions by calling appropriate player methods. The playback state of the media session is automatically synced with the player. The connector can also be optionally extended by providing various collaborators:
- Actions to initiate media playback (
PlaybackStateCompat#ACTION_PREPARE_*andPlaybackStateCompat#ACTION_PLAY_*) can be handled by aMediaSessionConnector.PlaybackPreparerpassed tosetPlaybackPreparer(PlaybackPreparer). - Custom actions can be handled by passing one or more
MediaSessionConnector.CustomActionProviders tosetCustomActionProviders(CustomActionProvider...). - To enable a media queue and navigation within it, you can set a
MediaSessionConnector.QueueNavigatorby callingsetQueueNavigator(QueueNavigator). Use ofTimelineQueueNavigatoris recommended for most use cases. - To enable editing of the media queue, you can set a
MediaSessionConnector.QueueEditorby callingsetQueueEditor(QueueEditor). - A
MediaSessionConnector.MediaButtonEventHandlercan be set by callingsetMediaButtonEventHandler(MediaButtonEventHandler). By default media button events are handled byMediaSessionCompat.Callback.onMediaButtonEvent(Intent). - An
ErrorMessageProviderfor providing human readable error messages and corresponding error codes can be set by callingsetErrorMessageProvider(ErrorMessageProvider). - A
MediaSessionConnector.MediaMetadataProvidercan be set by callingsetMediaMetadataProvider(MediaMetadataProvider). By default theMediaSessionConnector.DefaultMediaMetadataProvideris used.
- Actions to initiate media playback (
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceMediaSessionConnector.CaptionCallbackDeprecated.Handles requests for enabling or disabling captions.static interfaceMediaSessionConnector.CommandReceiverDeprecated.Receiver of media commands sent by a media controller.static interfaceMediaSessionConnector.CustomActionProviderDeprecated.Provides aPlaybackStateCompat.CustomActionto be published and handles the action when sent by a media controller.static classMediaSessionConnector.DefaultMediaMetadataProviderDeprecated.Provides a defaultMediaMetadataCompatwith properties and extras taken from theMediaDescriptionCompatof theMediaSessionCompat.QueueItemof the active queue item.static interfaceMediaSessionConnector.MediaButtonEventHandlerDeprecated.Handles a media button event.static interfaceMediaSessionConnector.MediaMetadataProviderDeprecated.Provides aMediaMetadataCompatfor a given player state.static interfaceMediaSessionConnector.PlaybackActionsDeprecated.Playback actions supported by the connector.static interfaceMediaSessionConnector.PlaybackPreparerDeprecated.Interface to which playback preparation and play actions are delegated.static interfaceMediaSessionConnector.QueueEditorDeprecated.Handles media session queue edits.static interfaceMediaSessionConnector.QueueNavigatorDeprecated.Handles queue navigation actions, and updates the media session queue by callingMediaSessionCompat.setQueue().static interfaceMediaSessionConnector.RatingCallbackDeprecated.Callback receiving a user rating for the active media item.
-
Field Summary
Fields Modifier and Type Field Description static longALL_PLAYBACK_ACTIONSDeprecated.static longDEFAULT_PLAYBACK_ACTIONSDeprecated.The default playback actions.static StringEXTRAS_SPEEDDeprecated.The name of thePlaybackStateCompatfloat extra with the value ofPlayer.getPlaybackParameters().speed.android.support.v4.media.session.MediaSessionCompatmediaSessionDeprecated.The wrappedMediaSessionCompat.
-
Constructor Summary
Constructors Constructor Description MediaSessionConnector(android.support.v4.media.session.MediaSessionCompat mediaSession)Deprecated.Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidinvalidateMediaSessionMetadata()Deprecated.Updates the metadata of the media session.voidinvalidateMediaSessionPlaybackState()Deprecated.Updates the playback state of the media session.voidinvalidateMediaSessionQueue()Deprecated.Updates the queue of the media session by callingMediaSessionConnector.QueueNavigator.onTimelineChanged(Player).voidregisterCustomCommandReceiver(MediaSessionConnector.CommandReceiver commandReceiver)Deprecated.Registers a custom command receiver for responding to commands delivered viaMediaSessionCompat.Callback.onCommand(String, Bundle, ResultReceiver).voidsetCaptionCallback(MediaSessionConnector.CaptionCallback captionCallback)Deprecated.Sets theMediaSessionConnector.CaptionCallbackto handle requests to enable or disable captions.voidsetClearMediaItemsOnStop(boolean clearMediaItemsOnStop)Deprecated.Sets whether media items are cleared from the playlist when a client sends aMediaControllerCompat.TransportControls.stop()command.voidsetCustomActionProviders(MediaSessionConnector.CustomActionProvider... customActionProviders)Deprecated.Sets custom action providers.voidsetCustomErrorMessage(CharSequence message)Deprecated.Sets a custom error on the session.voidsetCustomErrorMessage(CharSequence message, int code)Deprecated.Sets a custom error on the session.voidsetCustomErrorMessage(CharSequence message, int code, Bundle extras)Deprecated.Sets a custom error on the session.voidsetDispatchUnsupportedActionsEnabled(boolean dispatchUnsupportedActionsEnabled)Deprecated.Sets whether actions that are not advertised to theMediaSessionCompatwill be dispatched either way.voidsetEnabledPlaybackActions(long enabledPlaybackActions)Deprecated.Sets the enabled playback actions.voidsetErrorMessageProvider(ErrorMessageProvider<? super PlaybackException> errorMessageProvider)Deprecated.Sets the optionalErrorMessageProvider.voidsetMapStateIdleToSessionStateStopped(boolean mapIdleToStopped)Deprecated.Sets whetherPlayer.STATE_IDLEshould be mapped toPlaybackStateCompat.STATE_STOPPED.voidsetMediaButtonEventHandler(MediaSessionConnector.MediaButtonEventHandler mediaButtonEventHandler)Deprecated.voidsetMediaMetadataProvider(MediaSessionConnector.MediaMetadataProvider mediaMetadataProvider)Deprecated.Sets a provider of metadata to be published to the media session.voidsetMetadataDeduplicationEnabled(boolean metadataDeduplicationEnabled)Deprecated.Sets whetherMediaSessionConnector.MediaMetadataProvider.sameAs(MediaMetadataCompat, MediaMetadataCompat)should be consulted before callingMediaSessionCompat.setMetadata(MediaMetadataCompat).voidsetPlaybackPreparer(MediaSessionConnector.PlaybackPreparer playbackPreparer)Deprecated.Sets theMediaSessionConnector.PlaybackPreparer.voidsetPlayer(Player player)Deprecated.Sets the player to be connected to the media session.voidsetQueueEditor(MediaSessionConnector.QueueEditor queueEditor)Deprecated.Sets theMediaSessionConnector.QueueEditorto handle queue edits sent by the media controller.voidsetQueueNavigator(MediaSessionConnector.QueueNavigator queueNavigator)Deprecated.Sets theMediaSessionConnector.QueueNavigatorto handle queue navigation actionsACTION_SKIP_TO_NEXT,ACTION_SKIP_TO_PREVIOUSandACTION_SKIP_TO_QUEUE_ITEM.voidsetRatingCallback(MediaSessionConnector.RatingCallback ratingCallback)Deprecated.Sets theMediaSessionConnector.RatingCallbackto handle user ratings.voidunregisterCustomCommandReceiver(MediaSessionConnector.CommandReceiver commandReceiver)Deprecated.Unregisters a previously registered custom command receiver.
-
-
-
Field Detail
-
ALL_PLAYBACK_ACTIONS
public static final long ALL_PLAYBACK_ACTIONS
Deprecated.- See Also:
- Constant Field Values
-
DEFAULT_PLAYBACK_ACTIONS
public static final long DEFAULT_PLAYBACK_ACTIONS
Deprecated.The default playback actions.- See Also:
- Constant Field Values
-
EXTRAS_SPEED
public static final String EXTRAS_SPEED
Deprecated.The name of thePlaybackStateCompatfloat extra with the value ofPlayer.getPlaybackParameters().speed.- See Also:
- Constant Field Values
-
mediaSession
public final android.support.v4.media.session.MediaSessionCompat mediaSession
Deprecated.The wrappedMediaSessionCompat.
-
-
Method Detail
-
setPlayer
public void setPlayer(@Nullable Player player)Deprecated.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 theMediaSession, ornullto disconnect the current player.
-
setPlaybackPreparer
public void setPlaybackPreparer(@Nullable MediaSessionConnector.PlaybackPreparer playbackPreparer)Deprecated.Sets theMediaSessionConnector.PlaybackPreparer.- Parameters:
playbackPreparer- TheMediaSessionConnector.PlaybackPreparer.
-
setMediaButtonEventHandler
public void setMediaButtonEventHandler(@Nullable MediaSessionConnector.MediaButtonEventHandler mediaButtonEventHandler)Deprecated.Sets theMediaSessionConnector.MediaButtonEventHandler. Passnullif the media button event should be handled byMediaSessionCompat.Callback.onMediaButtonEvent(Intent).Please note that prior to API 21 MediaButton events are not delivered to the
MediaSessionCompat. Instead they are delivered as key events (see 'Responding to media buttons'). In anActivity, media button events arrive at theActivity.dispatchKeyEvent(KeyEvent)method.If you are running the player in a foreground service (prior to API 21), you can create an intent filter and handle the
android.intent.action.MEDIA_BUTTONaction yourself. See Service handling ACTION_MEDIA_BUTTON for more information.- Parameters:
mediaButtonEventHandler- TheMediaSessionConnector.MediaButtonEventHandler, or null to let the event be handled byMediaSessionCompat.Callback.onMediaButtonEvent(Intent).
-
setEnabledPlaybackActions
public void setEnabledPlaybackActions(long enabledPlaybackActions)
Deprecated.Sets the enabled playback actions.- Parameters:
enabledPlaybackActions- The enabled playback actions.
-
setErrorMessageProvider
public void setErrorMessageProvider(@Nullable ErrorMessageProvider<? super PlaybackException> errorMessageProvider)Deprecated.Sets the optionalErrorMessageProvider.- Parameters:
errorMessageProvider- The error message provider.
-
setQueueNavigator
public void setQueueNavigator(@Nullable MediaSessionConnector.QueueNavigator queueNavigator)Deprecated.Sets theMediaSessionConnector.QueueNavigatorto handle queue navigation actionsACTION_SKIP_TO_NEXT,ACTION_SKIP_TO_PREVIOUSandACTION_SKIP_TO_QUEUE_ITEM.- Parameters:
queueNavigator- The queue navigator.
-
setQueueEditor
public void setQueueEditor(@Nullable MediaSessionConnector.QueueEditor queueEditor)Deprecated.Sets theMediaSessionConnector.QueueEditorto handle queue edits sent by the media controller.- Parameters:
queueEditor- The queue editor.
-
setRatingCallback
public void setRatingCallback(@Nullable MediaSessionConnector.RatingCallback ratingCallback)Deprecated.Sets theMediaSessionConnector.RatingCallbackto handle user ratings.- Parameters:
ratingCallback- The rating callback.
-
setCaptionCallback
public void setCaptionCallback(@Nullable MediaSessionConnector.CaptionCallback captionCallback)Deprecated.Sets theMediaSessionConnector.CaptionCallbackto handle requests to enable or disable captions.- Parameters:
captionCallback- The caption callback.
-
setCustomErrorMessage
public void setCustomErrorMessage(@Nullable CharSequence message)Deprecated.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 toPlaybackStateCompat.ERROR_CODE_APP_ERROR.- Parameters:
message- The error string to report ornullto clear the error.
-
setCustomErrorMessage
public void setCustomErrorMessage(@Nullable CharSequence message, int code)Deprecated.Sets a custom error on the session.- Parameters:
message- The error string to report ornullto clear the error.code- The error code to report. Ignored whenmessageisnull.
-
setCustomErrorMessage
public void setCustomErrorMessage(@Nullable CharSequence message, int code, @Nullable Bundle extras)Deprecated.Sets a custom error on the session.- Parameters:
message- The error string to report ornullto clear the error.code- The error code to report. Ignored whenmessageisnull.extras- Extras to include in reportedPlaybackStateCompat.
-
setCustomActionProviders
public void setCustomActionProviders(@Nullable MediaSessionConnector.CustomActionProvider... customActionProviders)Deprecated.Sets custom action providers. The order of theMediaSessionConnector.CustomActionProviders determines the order in which the actions are published.- Parameters:
customActionProviders- The custom action providers, or null to remove all existing custom action providers.
-
setMediaMetadataProvider
public void setMediaMetadataProvider(@Nullable MediaSessionConnector.MediaMetadataProvider mediaMetadataProvider)Deprecated.Sets a provider of metadata to be published to the media session. Passnullif no metadata should be published.- Parameters:
mediaMetadataProvider- The provider of metadata to publish, ornullif no metadata should be published.
-
setDispatchUnsupportedActionsEnabled
public void setDispatchUnsupportedActionsEnabled(boolean dispatchUnsupportedActionsEnabled)
Deprecated.Sets whether actions that are not advertised to theMediaSessionCompatwill be dispatched either way. Default value is false.
-
setClearMediaItemsOnStop
public void setClearMediaItemsOnStop(boolean clearMediaItemsOnStop)
Deprecated.Sets whether media items are cleared from the playlist when a client sends aMediaControllerCompat.TransportControls.stop()command.
-
setMapStateIdleToSessionStateStopped
public void setMapStateIdleToSessionStateStopped(boolean mapIdleToStopped)
Deprecated.Sets whetherPlayer.STATE_IDLEshould be mapped toPlaybackStateCompat.STATE_STOPPED. The default is falsePlayer.STATE_IDLEwhich maps toPlaybackStateCompat.STATE_NONE.
-
setMetadataDeduplicationEnabled
public void setMetadataDeduplicationEnabled(boolean metadataDeduplicationEnabled)
Deprecated.Sets whetherMediaSessionConnector.MediaMetadataProvider.sameAs(MediaMetadataCompat, MediaMetadataCompat)should be consulted before callingMediaSessionCompat.setMetadata(MediaMetadataCompat).Note that this comparison is normally only required when you are using media sources that may introduce duplicate updates of the metadata for the same media item (e.g. live streams).
- Parameters:
metadataDeduplicationEnabled- Whether to deduplicate metadata objects on invalidation.
-
invalidateMediaSessionMetadata
public final void invalidateMediaSessionMetadata()
Deprecated.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
MediaMetadataCompatwhich is published to the session is obtained by callingMediaSessionConnector.MediaMetadataProvider.getMetadata(Player).
-
invalidateMediaSessionPlaybackState
public final void invalidateMediaSessionPlaybackState()
Deprecated.Updates the playback state of the media session.Apps normally only need to call this method when the custom actions provided by a
MediaSessionConnector.CustomActionProviderchanged and the playback state needs to be updated immediately.
-
invalidateMediaSessionQueue
public final void invalidateMediaSessionQueue()
Deprecated.Updates the queue of the media session by callingMediaSessionConnector.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)Deprecated.Registers a custom command receiver for responding to commands delivered viaMediaSessionCompat.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)Deprecated.Unregisters a previously registered custom command receiver.- Parameters:
commandReceiver- The command receiver to unregister.
-
-