SessionResult

open class SessionResult : RemoteResult, VersionedParcelable
kotlin.Any
   ↳ androidx.media2.session.SessionResult

Result class to be used with ListenableFuture for asynchronous calls between MediaSession and MediaController.

Summary

Constants

static Int

Result code representing that the command is successfully completed.

Public constructors

<init>(resultCode: Int, @Nullable customCommandResult: Bundle?)

Constructor to be used by MediaSession.SessionCallback#onCustomCommand( * MediaSession, MediaSession.ControllerInfo, SessionCommand, Bundle).

Public methods

open Long

Gets the completion time of the command.

open Bundle?

Gets the result of MediaSession#sendCustomCommand(MediaSession.ControllerInfo, SessionCommand, Bundle) and MediaController#sendCustomCommand(SessionCommand, Bundle) only when this object is returned by one of them.

open MediaItem?

Gets the MediaItem for which the command was executed.

open Int

Gets the result code.

Constants

RESULT_SUCCESS

static val RESULT_SUCCESS: Int

Result code representing that the command is successfully completed.

Interoperability: This code is also used to tell that the command was successfully sent, but the result is unknown when connected with MediaSessionCompat or MediaControllerCompat.

Value: 0

Public constructors

<init>

SessionResult(resultCode: Int, @Nullable customCommandResult: Bundle?)

Constructor to be used by MediaSession.SessionCallback#onCustomCommand( * MediaSession, MediaSession.ControllerInfo, SessionCommand, Bundle).

Parameters
resultCode Int: result code
customCommandResult Int: custom command result.

Public methods

getCompletionTime

open fun getCompletionTime(): Long

Gets the completion time of the command. Being more specific, it's the same as SystemClock#elapsedRealtime() when the command completed.

Return
Long: completion time of the command

getCustomCommandResult

@Nullable open fun getCustomCommandResult(): Bundle?

Gets the result of MediaSession#sendCustomCommand(MediaSession.ControllerInfo, SessionCommand, Bundle) and MediaController#sendCustomCommand(SessionCommand, Bundle) only when this object is returned by one of them.

If this object is returned by other methods, this method will be null.

Return
Bundle?: result of sending custom command

getMediaItem

@Nullable open fun getMediaItem(): MediaItem?

Gets the MediaItem for which the command was executed. In other words, this is the current media item when the command completed.

Can be null for many reasons. For examples,

  • Error happened.
  • Current media item was null at that time.
  • Command is irrelevant with the media item (e.g. custom command).
Return
MediaItem?: media item when the command completed. Can be null for an error, the current media item was null, or any other reason.