public
class
RemoteControlClient
extends Object
java.lang.Object | |
↳ | android.media.RemoteControlClient |
This class was deprecated
in API level 21.
Use MediaSession
instead.
RemoteControlClient enables exposing information meant to be consumed by remote controls capable of displaying metadata, artwork and media transport control buttons.
A remote control client object is associated with a media button event receiver. This
event receiver must have been previously registered with
registerMediaButtonEventReceiver(ComponentName)
before the
RemoteControlClient can be registered through
registerRemoteControlClient(RemoteControlClient)
.
Here is an example of creating a RemoteControlClient instance after registering a media button event receiver:
ComponentName myEventReceiver = new ComponentName(getPackageName(), MyRemoteControlEventReceiver.class.getName()); AudioManager myAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); myAudioManager.registerMediaButtonEventReceiver(myEventReceiver); // build the PendingIntent for the remote control client Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); mediaButtonIntent.setComponent(myEventReceiver); PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, mediaButtonIntent, 0); // create and register the remote control client RemoteControlClient myRemoteControlClient = new RemoteControlClient(mediaPendingIntent); myAudioManager.registerRemoteControlClient(myRemoteControlClient);
Nested classes | |
---|---|
class |
RemoteControlClient.MetadataEditor
This class was deprecated
in API level 21.
Use |
interface |
RemoteControlClient.OnGetPlaybackPositionListener
Interface definition for a callback to be invoked when the media playback position is queried. |
interface |
RemoteControlClient.OnMetadataUpdateListener
Interface definition for a callback to be invoked when one of the metadata values has been updated. |
interface |
RemoteControlClient.OnPlaybackPositionUpdateListener
Interface definition for a callback to be invoked when the media playback position is requested to be updated. |
Constants | |
---|---|
int |
FLAG_KEY_MEDIA_FAST_FORWARD
Flag indicating a RemoteControlClient makes use of the "fast forward" media key. |
int |
FLAG_KEY_MEDIA_NEXT
Flag indicating a RemoteControlClient makes use of the "next" media key. |
int |
FLAG_KEY_MEDIA_PAUSE
Flag indicating a RemoteControlClient makes use of the "pause" media key. |
int |
FLAG_KEY_MEDIA_PLAY
Flag indicating a RemoteControlClient makes use of the "play" media key. |
int |
FLAG_KEY_MEDIA_PLAY_PAUSE
Flag indicating a RemoteControlClient makes use of the "play/pause" media key. |
int |
FLAG_KEY_MEDIA_POSITION_UPDATE
Flag indicating a RemoteControlClient can receive changes in the media playback position
through the |
int |
FLAG_KEY_MEDIA_PREVIOUS
Flag indicating a RemoteControlClient makes use of the "previous" media key. |
int |
FLAG_KEY_MEDIA_RATING
Flag indicating a RemoteControlClient supports ratings. |
int |
FLAG_KEY_MEDIA_REWIND
Flag indicating a RemoteControlClient makes use of the "rewind" media key. |
int |
FLAG_KEY_MEDIA_STOP
Flag indicating a RemoteControlClient makes use of the "stop" media key. |
int |
PLAYSTATE_BUFFERING
Playback state of a RemoteControlClient which is buffering data to play before it can start or resume playback. |
int |
PLAYSTATE_ERROR
Playback state of a RemoteControlClient which cannot perform any playback related operation because of an internal error. |
int |
PLAYSTATE_FAST_FORWARDING
Playback state of a RemoteControlClient which is fast forwarding in the media it is currently playing. |
int |
PLAYSTATE_PAUSED
Playback state of a RemoteControlClient which is paused. |
int |
PLAYSTATE_PLAYING
Playback state of a RemoteControlClient which is playing media. |
int |
PLAYSTATE_REWINDING
Playback state of a RemoteControlClient which is fast rewinding in the media it is currently playing. |
int |
PLAYSTATE_SKIPPING_BACKWARDS
Playback state of a RemoteControlClient which is skipping back to the previous logical chapter (such as a song in a playlist) in the media it is currently playing. |
int |
PLAYSTATE_SKIPPING_FORWARDS
Playback state of a RemoteControlClient which is skipping to the next logical chapter (such as a song in a playlist) in the media it is currently playing. |
int |
PLAYSTATE_STOPPED
Playback state of a RemoteControlClient which is stopped. |
Public constructors | |
---|---|
RemoteControlClient(PendingIntent mediaButtonIntent)
Class constructor. |
|
RemoteControlClient(PendingIntent mediaButtonIntent, Looper looper)
Class constructor for a remote control client whose internal event handling happens on a user-provided Looper. |
Public methods | |
---|---|
RemoteControlClient.MetadataEditor
|
editMetadata(boolean startEmpty)
Creates a |
MediaSession
|
getMediaSession()
Get a |
void
|
setMetadataUpdateListener(RemoteControlClient.OnMetadataUpdateListener l)
Sets the listener to be called whenever the metadata is updated. |
void
|
setOnGetPlaybackPositionListener(RemoteControlClient.OnGetPlaybackPositionListener l)
Sets the listener to be called whenever the media current playback position is needed. |
void
|
setPlaybackPositionUpdateListener(RemoteControlClient.OnPlaybackPositionUpdateListener l)
Sets the listener to be called whenever the media playback position is requested to be updated. |
void
|
setPlaybackState(int state, long timeInMs, float playbackSpeed)
Sets the current playback state and the matching media position for the current playback speed. |
void
|
setPlaybackState(int state)
Sets the current playback state. |
void
|
setTransportControlFlags(int transportControlFlags)
Sets the flags for the media transport control buttons that this client supports. |
Inherited methods | |
---|---|
From
class
java.lang.Object
|
int FLAG_KEY_MEDIA_FAST_FORWARD
Flag indicating a RemoteControlClient makes use of the "fast forward" media key.
Constant Value: 64 (0x00000040)
int FLAG_KEY_MEDIA_NEXT
Flag indicating a RemoteControlClient makes use of the "next" media key.
Constant Value: 128 (0x00000080)
int FLAG_KEY_MEDIA_PAUSE
Flag indicating a RemoteControlClient makes use of the "pause" media key.
Constant Value: 16 (0x00000010)
int FLAG_KEY_MEDIA_PLAY
Flag indicating a RemoteControlClient makes use of the "play" media key.
Constant Value: 4 (0x00000004)
int FLAG_KEY_MEDIA_PLAY_PAUSE
Flag indicating a RemoteControlClient makes use of the "play/pause" media key.
Constant Value: 8 (0x00000008)
int FLAG_KEY_MEDIA_POSITION_UPDATE
Flag indicating a RemoteControlClient can receive changes in the media playback position
through the RemoteControlClient.OnPlaybackPositionUpdateListener
interface. This flag must be set
in order for components that display the RemoteControlClient information, to display and
let the user control media playback position.
See also:
Constant Value: 256 (0x00000100)
int FLAG_KEY_MEDIA_PREVIOUS
Flag indicating a RemoteControlClient makes use of the "previous" media key.
Constant Value: 1 (0x00000001)
int FLAG_KEY_MEDIA_RATING
Flag indicating a RemoteControlClient supports ratings.
This flag must be set in order for components that display the RemoteControlClient
information, to display ratings information, and, if ratings are declared editable
(by calling addEditableKey(int)
with the
RATING_KEY_BY_USER
key), it will enable the user to rate
the media, with values being received through the interface set with
setMetadataUpdateListener(OnMetadataUpdateListener)
.
See also:
Constant Value: 512 (0x00000200)
int FLAG_KEY_MEDIA_REWIND
Flag indicating a RemoteControlClient makes use of the "rewind" media key.
Constant Value: 2 (0x00000002)
int FLAG_KEY_MEDIA_STOP
Flag indicating a RemoteControlClient makes use of the "stop" media key.
Constant Value: 32 (0x00000020)
int PLAYSTATE_BUFFERING
Playback state of a RemoteControlClient which is buffering data to play before it can start or resume playback.
See also:
Constant Value: 8 (0x00000008)
int PLAYSTATE_ERROR
Playback state of a RemoteControlClient which cannot perform any playback related operation because of an internal error. Examples of such situations are no network connectivity when attempting to stream data from a server, or expired user credentials when trying to play subscription-based content.
See also:
Constant Value: 9 (0x00000009)
int PLAYSTATE_FAST_FORWARDING
Playback state of a RemoteControlClient which is fast forwarding in the media it is currently playing.
See also:
Constant Value: 4 (0x00000004)
int PLAYSTATE_PAUSED
Playback state of a RemoteControlClient which is paused.
See also:
Constant Value: 2 (0x00000002)
int PLAYSTATE_PLAYING
Playback state of a RemoteControlClient which is playing media.
See also:
Constant Value: 3 (0x00000003)
int PLAYSTATE_REWINDING
Playback state of a RemoteControlClient which is fast rewinding in the media it is currently playing.
See also:
Constant Value: 5 (0x00000005)
int PLAYSTATE_SKIPPING_BACKWARDS
Playback state of a RemoteControlClient which is skipping back to the previous logical chapter (such as a song in a playlist) in the media it is currently playing.
See also:
Constant Value: 7 (0x00000007)
int PLAYSTATE_SKIPPING_FORWARDS
Playback state of a RemoteControlClient which is skipping to the next logical chapter (such as a song in a playlist) in the media it is currently playing.
See also:
Constant Value: 6 (0x00000006)
int PLAYSTATE_STOPPED
Playback state of a RemoteControlClient which is stopped.
See also:
Constant Value: 1 (0x00000001)
RemoteControlClient (PendingIntent mediaButtonIntent)
Class constructor.
Parameters | |
---|---|
mediaButtonIntent |
PendingIntent :
The intent that will be sent for the media button events sent
by remote controls.
This intent needs to have been constructed with the ACTION_MEDIA_BUTTON
action, and have a component that will handle the intent (set with
setComponent(ComponentName) ) registered with
registerMediaButtonEventReceiver(ComponentName)
before this new RemoteControlClient can itself be registered with
registerRemoteControlClient(RemoteControlClient) . |
RemoteControlClient (PendingIntent mediaButtonIntent, Looper looper)
Class constructor for a remote control client whose internal event handling happens on a user-provided Looper.
Parameters | |
---|---|
mediaButtonIntent |
PendingIntent :
The intent that will be sent for the media button events sent
by remote controls.
This intent needs to have been constructed with the ACTION_MEDIA_BUTTON
action, and have a component that will handle the intent (set with
setComponent(ComponentName) ) registered with
registerMediaButtonEventReceiver(ComponentName)
before this new RemoteControlClient can itself be registered with
registerRemoteControlClient(RemoteControlClient) . |
looper |
Looper :
The Looper running the event loop. |
RemoteControlClient.MetadataEditor editMetadata (boolean startEmpty)
Creates a RemoteControlClient.MetadataEditor
.
Parameters | |
---|---|
startEmpty |
boolean :
Set to false if you want the MetadataEditor to contain the metadata that
was previously applied to the RemoteControlClient, or true if it is to be created empty. |
Returns | |
---|---|
RemoteControlClient.MetadataEditor |
a new MetadataEditor instance. |
MediaSession getMediaSession ()
Get a MediaSession
associated with this RCC. It will only have a
session while it is registered with
registerRemoteControlClient(RemoteControlClient)
. The session returned
should not be modified directly by the application but may be used with
other APIs that require a session.
Returns | |
---|---|
MediaSession |
A media session object or null. |
void setMetadataUpdateListener (RemoteControlClient.OnMetadataUpdateListener l)
Sets the listener to be called whenever the metadata is updated. New metadata values will be received in the same thread as the one in which RemoteControlClient was created.
Parameters | |
---|---|
l |
RemoteControlClient.OnMetadataUpdateListener :
the metadata update listener
|
void setOnGetPlaybackPositionListener (RemoteControlClient.OnGetPlaybackPositionListener l)
Sets the listener to be called whenever the media current playback position is needed. Queries will be received in the same thread as the one in which RemoteControlClient was created.
Parameters | |
---|---|
l |
RemoteControlClient.OnGetPlaybackPositionListener :
the listener to be called to retrieve the playback position
|
void setPlaybackPositionUpdateListener (RemoteControlClient.OnPlaybackPositionUpdateListener l)
Sets the listener to be called whenever the media playback position is requested to be updated. Notifications will be received in the same thread as the one in which RemoteControlClient was created.
Parameters | |
---|---|
l |
RemoteControlClient.OnPlaybackPositionUpdateListener :
the position update listener to be called
|
void setPlaybackState (int state, long timeInMs, float playbackSpeed)
Sets the current playback state and the matching media position for the current playback speed.
Parameters | |
---|---|
state |
int :
The current playback state, one of the following values:
PLAYSTATE_STOPPED ,
PLAYSTATE_PAUSED ,
PLAYSTATE_PLAYING ,
PLAYSTATE_FAST_FORWARDING ,
PLAYSTATE_REWINDING ,
PLAYSTATE_SKIPPING_FORWARDS ,
PLAYSTATE_SKIPPING_BACKWARDS ,
PLAYSTATE_BUFFERING ,
PLAYSTATE_ERROR . |
timeInMs |
long :
a 0 or positive value for the current media position expressed in ms
(same unit as for when sending the media duration, if applicable, with
METADATA_KEY_DURATION in the
RemoteControlClient.MetadataEditor ). Negative values imply that position is not
known (e.g. listening to a live stream of a radio) or not applicable (e.g. when state
is PLAYSTATE_BUFFERING and nothing had played yet). |
playbackSpeed |
float :
a value expressed as a ratio of 1x playback: 1.0f is normal playback,
2.0f is 2x, 0.5f is half-speed, -2.0f is rewind at 2x speed. 0.0f means nothing is
playing (e.g. when state is PLAYSTATE_ERROR ).
|
void setPlaybackState (int state)
Sets the current playback state.
Parameters | |
---|---|
state |
int :
The current playback state, one of the following values:
PLAYSTATE_STOPPED ,
PLAYSTATE_PAUSED ,
PLAYSTATE_PLAYING ,
PLAYSTATE_FAST_FORWARDING ,
PLAYSTATE_REWINDING ,
PLAYSTATE_SKIPPING_FORWARDS ,
PLAYSTATE_SKIPPING_BACKWARDS ,
PLAYSTATE_BUFFERING ,
PLAYSTATE_ERROR .
|
void setTransportControlFlags (int transportControlFlags)
Sets the flags for the media transport control buttons that this client supports.
Parameters | |
---|---|
transportControlFlags |
int :
A combination of the following flags:
FLAG_KEY_MEDIA_PREVIOUS ,
FLAG_KEY_MEDIA_REWIND ,
FLAG_KEY_MEDIA_PLAY ,
FLAG_KEY_MEDIA_PLAY_PAUSE ,
FLAG_KEY_MEDIA_PAUSE ,
FLAG_KEY_MEDIA_STOP ,
FLAG_KEY_MEDIA_FAST_FORWARD ,
FLAG_KEY_MEDIA_NEXT ,
FLAG_KEY_MEDIA_POSITION_UPDATE ,
FLAG_KEY_MEDIA_RATING .
|