Added in API level 19
Deprecated in API level 21

RemoteController


class RemoteController
kotlin.Any
   ↳ android.media.RemoteController

The RemoteController class is used to control media playback, display and update media metadata and playback status, published by applications using the RemoteControlClient class.

A RemoteController shall be registered through AudioManager#registerRemoteController(RemoteController) in order for the system to send media event updates to the OnClientUpdateListener listener set in the class constructor. Implement the methods of the interface to receive the information published by the active RemoteControlClient instances.
By default an OnClientUpdateListener implementation will not receive bitmaps for album art. Use setArtworkConfiguration(int,int) to receive images as well.

Registration requires the OnClientUpdateListener listener to be one of the enabled notification listeners (see android.service.notification.NotificationListenerService).

Summary

Nested classes

A class to read the metadata published by a RemoteControlClient, or send a RemoteControlClient new values for keys that can be edited.

abstract

Interface definition for the callbacks to be invoked whenever media events, metadata and playback status are available.

Constants
static Int

The playback position synchronization mode where the RemoteControlClient instances which expose their playback position to the framework, will be regularly polled to check whether any drift has been noticed between their estimated position and the one they report.

static Int

Default playback position synchronization mode where the RemoteControlClient is not asked regularly for its playback position to see if it has drifted from the estimated position.

Public constructors

Class constructor.

Class constructor.

Public methods
Boolean

Prevents this RemoteController from receiving artwork images.

RemoteController.MetadataEditor!

Creates a MetadataEditor for updating metadata values of the editable keys of the current RemoteControlClient.

Long

Return the estimated playback position of the current media track or a negative value if not available.

Boolean
seekTo(timeMs: Long)

Sets the new playback position.

Boolean

Send a simulated key event for a media button to be received by the current client.

Boolean
setArtworkConfiguration(width: Int, height: Int)

Set the maximum artwork image dimensions to be received in the metadata.

Boolean

Set the playback position synchronization mode.

Constants

POSITION_SYNCHRONIZATION_CHECK

Added in API level 19
static val POSITION_SYNCHRONIZATION_CHECK: Int

Deprecated: Deprecated in Java.

The playback position synchronization mode where the RemoteControlClient instances which expose their playback position to the framework, will be regularly polled to check whether any drift has been noticed between their estimated position and the one they report. Note that this mode should only ever be used when needing to display very accurate playback position, as regularly polling a RemoteControlClient for its position may have an impact on battery life (if applicable) when this query will trigger network transactions in the case of remote playback.

Value: 1

POSITION_SYNCHRONIZATION_NONE

Added in API level 19
static val POSITION_SYNCHRONIZATION_NONE: Int

Deprecated: Deprecated in Java.

Default playback position synchronization mode where the RemoteControlClient is not asked regularly for its playback position to see if it has drifted from the estimated position.

Value: 0

Public constructors

RemoteController

Added in API level 19
RemoteController(
    context: Context!,
    updateListener: RemoteController.OnClientUpdateListener!)

Class constructor.

Parameters
context Context!: the Context, must be non-null.
updateListener RemoteController.OnClientUpdateListener!: the listener to be called whenever new client information is available, must be non-null.
Exceptions
java.lang.IllegalArgumentException

RemoteController

Added in API level 19
RemoteController(
    context: Context!,
    updateListener: RemoteController.OnClientUpdateListener!,
    looper: Looper!)

Class constructor.

Parameters
context Context!: the Context, must be non-null.
updateListener RemoteController.OnClientUpdateListener!: the listener to be called whenever new client information is available, must be non-null.
looper Looper!: the Looper on which to run the event loop, or null to use the current thread's looper.
Exceptions
java.lang.IllegalArgumentException

Public methods

clearArtworkConfiguration

Added in API level 19
fun clearArtworkConfiguration(): Boolean

Deprecated: Deprecated in Java.

Prevents this RemoteController from receiving artwork images.

Return
Boolean true if receiving artwork images was successfully disabled.

editMetadata

Added in API level 19
fun editMetadata(): RemoteController.MetadataEditor!

Deprecated: Deprecated in Java.

Creates a MetadataEditor for updating metadata values of the editable keys of the current RemoteControlClient. This method can only be called on a registered RemoteController.

Return
RemoteController.MetadataEditor! a new MetadataEditor instance.

getEstimatedMediaPosition

Added in API level 19
fun getEstimatedMediaPosition(): Long

Deprecated: Deprecated in Java.

Return the estimated playback position of the current media track or a negative value if not available.

The value returned is estimated by the current process and may not be perfect. The time returned by this method is calculated from the last state change time based on the current play position at that time and the last known playback speed. An application may call setSynchronizationMode(int) to apply a synchronization policy that will periodically re-sync the estimated position with the RemoteControlClient.

Return
Long the current estimated playback position in milliseconds or a negative value if not available

seekTo

Added in API level 19
fun seekTo(timeMs: Long): Boolean

Deprecated: Deprecated in Java.

Sets the new playback position. This method can only be called on a registered RemoteController.

Parameters
timeMs Long: a 0 or positive value for the new playback position, expressed in ms.
Return
Boolean true if the command to set the playback position was successfully sent.
Exceptions
java.lang.IllegalArgumentException

sendMediaKeyEvent

Added in API level 19
fun sendMediaKeyEvent(keyEvent: KeyEvent!): Boolean

Deprecated: Deprecated in Java.

Send a simulated key event for a media button to be received by the current client. To simulate a key press, you must first send a KeyEvent built with a android.view.KeyEvent#ACTION_DOWN action, then another event with the KeyEvent#ACTION_UP action.

The key event will be sent to the registered receiver (see android.media.AudioManager#registerMediaButtonEventReceiver(PendingIntent)) whose associated RemoteControlClient's metadata and playback state is published (there may be none under some circumstances).

Parameters
keyEvent KeyEvent!: a media session KeyEvent, as defined by android.view.KeyEvent#isMediaSessionKey.
Return
Boolean true if the event was successfully sent, false otherwise.
Exceptions
java.lang.IllegalArgumentException If the provided KeyEvent is not a media session key, as defined by KeyEvent#isMediaSessionKey.

setArtworkConfiguration

Added in API level 19
fun setArtworkConfiguration(
    width: Int,
    height: Int
): Boolean

Deprecated: Deprecated in Java.

Set the maximum artwork image dimensions to be received in the metadata. No bitmaps will be received unless this has been specified.

Parameters
width Int: the maximum width in pixels
height Int: the maximum height in pixels
Return
Boolean true if the artwork dimension was successfully set.
Exceptions
java.lang.IllegalArgumentException

setSynchronizationMode

Added in API level 19
fun setSynchronizationMode(sync: Int): Boolean

Deprecated: Deprecated in Java.

Set the playback position synchronization mode. Must be called on a registered RemoteController.

Parameters
sync Int: POSITION_SYNCHRONIZATION_NONE or POSITION_SYNCHRONIZATION_CHECK
Return
Boolean true if the synchronization mode was successfully set.
Exceptions
java.lang.IllegalArgumentException