MediaManager

public class MediaManager extends Object

Manager class for all media status and commands.

This class is responsible to translate media namespace messages from senders into media commands, and send media status back to the sender.

Nested Class Summary

interface MediaManager.MediaStatusInterceptor Interceptor interface for MediaStatus. 

Public Method Summary

void
broadcastMediaStatus()
Trigger a media status broadcast.
MediaStatus
getBaseMediaStatus()
Returns the base MediaStatus which is generated from Android MediaSession, before applying any overrides from MediaStatusModifier, MediaQueueManager or MediaManager.MediaStatusInterceptor.
MediaStatus
getCurrentMediaStatus()
Returns the current MediaStatus generated from the base MediaStatus with overrides applied from MediaStatusModifier and MediaQueueManager (note that changes from MediaManager.MediaStatusInterceptor is not applied).
MediaQueueManager
MediaStatusModifier
boolean
onNewIntent(Intent intent)
Passes a new activity intent to MediaManager.
void
setDataFromLoad(MediaLoadRequestData loadRequestData)
Initializes MediaStatusModifier and MediaQueueManager overrides using the information from a load request.
void
void
setMediaLoadCommandCallback(MediaLoadCommandCallback callback)
Sets the MediaLoadCommandCallback to handle load and resume session requests.
void
setMediaStatusInterceptor(MediaManager.MediaStatusInterceptor interceptor)
Sets the MediaManager.MediaStatusInterceptor to intercept and modify the MediaStatus before it is being sent out.
void
setSessionCompatToken(MediaSessionCompat.Token token)
Sets and attaches to a MediaSession token.

Inherited Method Summary

Public Methods

public void broadcastMediaStatus ()

Trigger a media status broadcast.

The broadcasted MediaStatus is generated in the following steps:

  1. The library generates the base MediaStatus based on the current MediaSessionCompat information.
  2. The library applies the overrides from MediaStatusModifier and MediaQueueManager.
  3. The library invokes the MediaManager.MediaStatusInterceptor to apply final changes to the MediaStatus.
  4. Send the MediaStatus to the senders.

public MediaStatus getBaseMediaStatus ()

Returns the base MediaStatus which is generated from Android MediaSession, before applying any overrides from MediaStatusModifier, MediaQueueManager or MediaManager.MediaStatusInterceptor.

Returns null if no MediaSession attached or no metadata or playback state from MediaSession.

The following common commands are always added to the base MediaStatus by default (You can still override these commands via the MediaStatusModifier):

public MediaStatus getCurrentMediaStatus ()

Returns the current MediaStatus generated from the base MediaStatus with overrides applied from MediaStatusModifier and MediaQueueManager (note that changes from MediaManager.MediaStatusInterceptor is not applied).

Returns null if no MediaSession attached or no metadata or playback state from MediaSession.

public MediaQueueManager getMediaQueueManager ()

Returns the MediaQueueManager.

See MediaQueueManager for details about the queue manager.

See broadcastMediaStatus() for how MediaStatus is processed.

public MediaStatusModifier getMediaStatusModifier ()

Returns the MediaStatusModifier.

See MediaStatusModifier for details about the modifier.

See broadcastMediaStatus() for how MediaStatus is processed.

public boolean onNewIntent (Intent intent)

Passes a new activity intent to MediaManager. If it is a supported load or resume session intent, it will be notified via callbacks in MediaCommandCallback.

Returns
  • true if the intent is handled by the SDK

public void setDataFromLoad (MediaLoadRequestData loadRequestData)

Initializes MediaStatusModifier and MediaQueueManager overrides using the information from a load request.

All current overrides in MediaStatusModifier and MediaQueueManager will be cleared after this method call.

See MediaStatusModifier.clear() about clearing overrides in MediaStatusModifier.

See MediaQueueManager.clear() about clearing overrides in MediaQueueManager.

See MediaQueueManager.autoGenerateItemId() about auto-generation of item IDs.

public void setMediaCommandCallback (MediaCommandCallback callback)

Sets the MediaCommandCallback. Setting to null resets to the default implementation.

The default implementation translates cast commands into MediaControllerCompat.TransportControls commands.

public void setMediaLoadCommandCallback (MediaLoadCommandCallback callback)

Sets the MediaLoadCommandCallback to handle load and resume session requests. Setting to null resets the default implementation.

The default implementation fails all requests.

public void setMediaStatusInterceptor (MediaManager.MediaStatusInterceptor interceptor)

Sets the MediaManager.MediaStatusInterceptor to intercept and modify the MediaStatus before it is being sent out.

The interceptor operates on a MediaStatus after applying overrides from MediaStatusModifier and MediaQueueManager.

public void setSessionCompatToken (MediaSessionCompat.Token token)

Sets and attaches to a MediaSession token. Setting to null detaches the library from the current MediaSession token.