Google is committed to advancing racial equity for Black communities. See how.

MediaCommandCallback

public class MediaCommandCallback extends Object

Callback for Cast media commands.

This class has the default implementation to call methods of the MediaSession which MediaManager currently attaches to.

Public Constructor Summary

Public Method Summary

Task<Void>
onEditAudioTracks(String senderId, EditAudioTracksData requestData)
Called when a edit audio tracks command is received.
Task<Void>
onEditTracksInfo(String senderId, EditTracksInfoData requestData)
Called when a edit tracks info command is received.
Task<Void>
onFetchItems(String senderId, FetchItemsRequestData requestData)
Called when a sender requests to fetch more items relative to an item.
Task<Void>
onPause(String senderId, RequestData requestData)
Called when a pause command is received.
Task<Void>
onPlay(String senderId, RequestData requestData)
Called when a play command is received.
Task<Void>
onPlayAgain(String senderId, RequestData requestData)
Called when assistant requests to play the last media again.
Task<Void>
onQueueInsert(String senderId, QueueInsertRequestData requestData)
Called when a queue insert command is received.
Task<Void>
onQueueRemove(String senderId, QueueRemoveRequestData requestData)
Called when a queue remove command is received.
Task<Void>
onQueueReorder(String senderId, QueueReorderRequestData requestData)
Called when a queue reorder command is received.
Task<Void>
onQueueUpdate(String senderId, QueueUpdateRequestData requestData)
Called when a queue update command is received.
Task<Void>
onSeek(String senderId, SeekRequestData requestData)
Called when a seek command is received.
Task<Void>
onSelectTracksByType(String senderId, int type, List<MediaTrack> tracks)
Called by default when a track-editing command is received, either onEditTracksInfo(String, EditTracksInfoData) or onEditAudioTracks(String, EditAudioTracksData), which requests to change the selected tracks.
Task<Void>
onSetPlaybackRate(String senderId, SetPlaybackRateRequestData requestData)
Called when a command is received to set the playback rate.
Task<Void>
onSetTextTrackStyle(String senderId, TextTrackStyle textTrackStyle)
Called by default when a track-editing command is received, which requests to change the text track style.
Task<Void>
onSkipAd(String senderId, RequestData requestData)
Called when a skip ad command is received.
Task<Void>
onStop(String senderId, RequestData requestData)
Called when a stop command is received.
Task<Void>
onUserAction(String senderId, UserActionRequestData userActionRequestData)
Called when the app receives a user action.

Inherited Method Summary

Public Constructors

public MediaCommandCallback ()

Public Methods

public Task<Void> onEditAudioTracks (String senderId, EditAudioTracksData requestData)

Called when a edit audio tracks command is received.

It is discouraged to override this method, unless you really need the original request data.

By default, this method will invoke onSelectTracksByType(String, int, List) with type TYPE_AUDIO with the first track matching the language, if getLanguage() is non-null.

public Task<Void> onEditTracksInfo (String senderId, EditTracksInfoData requestData)

Called when a edit tracks info command is received.

It is discouraged to override this method, unless you really need the original request data.

By default, this method will:

public Task<Void> onFetchItems (String senderId, FetchItemsRequestData requestData)

Called when a sender requests to fetch more items relative to an item.

public Task<Void> onPause (String senderId, RequestData requestData)

Called when a pause command is received.

The default implementation calls pause().

public Task<Void> onPlay (String senderId, RequestData requestData)

Called when a play command is received.

The default implementation calls play().

public Task<Void> onPlayAgain (String senderId, RequestData requestData)

Called when assistant requests to play the last media again.

public Task<Void> onQueueInsert (String senderId, QueueInsertRequestData requestData)

Called when a queue insert command is received.

public Task<Void> onQueueRemove (String senderId, QueueRemoveRequestData requestData)

Called when a queue remove command is received.

public Task<Void> onQueueReorder (String senderId, QueueReorderRequestData requestData)

Called when a queue reorder command is received.

public Task<Void> onQueueUpdate (String senderId, QueueUpdateRequestData requestData)

Called when a queue update command is received.

public Task<Void> onSeek (String senderId, SeekRequestData requestData)

Called when a seek command is received.

The default implementation calls seekTo(long).

public Task<Void> onSelectTracksByType (String senderId, int type, List<MediaTrack> tracks)

Called by default when a track-editing command is received, either onEditTracksInfo(String, EditTracksInfoData) or onEditAudioTracks(String, EditAudioTracksData), which requests to change the selected tracks.

This callback breaks down the original command, and scopes it to individual track types. Note that the full list of available tracks are obtained from the tracks set on the top-level MediaInfoModifier, which is set via setMediaTracks(List).

After you update the track selection in your app, you should call setActiveTracksByType(int, List) with tracks to update the track selection.

Parameters
senderId the ID of the sender requesting the change
type the type of the tracks to be changed
tracks the detailed track information for the tracks to be selected

public Task<Void> onSetPlaybackRate (String senderId, SetPlaybackRateRequestData requestData)

Called when a command is received to set the playback rate.

If the original request has getRelativePlaybackRate() is specified, it is automatically translated into getPlaybackRate() based on the current MediaStatus.

public Task<Void> onSetTextTrackStyle (String senderId, TextTrackStyle textTrackStyle)

Called by default when a track-editing command is received, which requests to change the text track style.

This is only called if the getTextTrackStyle() of the original request is non-null.

public Task<Void> onSkipAd (String senderId, RequestData requestData)

Called when a skip ad command is received.

public Task<Void> onStop (String senderId, RequestData requestData)

Called when a stop command is received.

The default implementation calls stop().

public Task<Void> onUserAction (String senderId, UserActionRequestData userActionRequestData)

Called when the app receives a user action.

Subclass should return a Task with a MediaError if there is any error when handling the action. Otherwise, return a Task with null.