public class RemoteControlClient extends Object
A remote control client object is associated with a media button event receiver. This
event receiver must have been previously registered with
AudioManager.registerMediaButtonEventReceiver(ComponentName)
before the
RemoteControlClient can be registered through
AudioManager.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);
Modifier and Type | Class and Description |
---|---|
class |
RemoteControlClient.MetadataEditor
Class used to modify metadata in a
RemoteControlClient object. |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PLAYBACK_VOLUME |
static int |
DEFAULT_PLAYBACK_VOLUME_HANDLING |
static int |
FLAG_INFORMATION_REQUEST_ALBUM_ART |
static int |
FLAG_INFORMATION_REQUEST_KEY_MEDIA |
static int |
FLAG_INFORMATION_REQUEST_METADATA |
static int |
FLAG_INFORMATION_REQUEST_PLAYSTATE |
static int |
FLAG_KEY_MEDIA_FAST_FORWARD
Flag indicating a RemoteControlClient makes use of the "fast forward" media key.
|
static int |
FLAG_KEY_MEDIA_NEXT
Flag indicating a RemoteControlClient makes use of the "next" media key.
|
static int |
FLAG_KEY_MEDIA_PAUSE
Flag indicating a RemoteControlClient makes use of the "pause" media key.
|
static int |
FLAG_KEY_MEDIA_PLAY
Flag indicating a RemoteControlClient makes use of the "play" media key.
|
static int |
FLAG_KEY_MEDIA_PLAY_PAUSE
Flag indicating a RemoteControlClient makes use of the "play/pause" media key.
|
static int |
FLAG_KEY_MEDIA_PREVIOUS
Flag indicating a RemoteControlClient makes use of the "previous" media key.
|
static int |
FLAG_KEY_MEDIA_REWIND
Flag indicating a RemoteControlClient makes use of the "rewind" media key.
|
static int |
FLAG_KEY_MEDIA_STOP
Flag indicating a RemoteControlClient makes use of the "stop" media key.
|
static int |
FLAGS_KEY_MEDIA_NONE |
static int |
PLAYBACK_TYPE_LOCAL |
static int |
PLAYBACK_TYPE_REMOTE |
static int |
PLAYBACK_VOLUME_FIXED |
static int |
PLAYBACK_VOLUME_VARIABLE |
static int |
PLAYBACKINFO_INVALID_VALUE |
static int |
PLAYBACKINFO_PLAYBACK_TYPE |
static int |
PLAYBACKINFO_PLAYSTATE |
static int |
PLAYBACKINFO_USES_STREAM |
static int |
PLAYBACKINFO_VOLUME |
static int |
PLAYBACKINFO_VOLUME_HANDLING |
static int |
PLAYBACKINFO_VOLUME_MAX |
static int |
PLAYSTATE_BUFFERING
Playback state of a RemoteControlClient which is buffering data to play before it can
start or resume playback.
|
static int |
PLAYSTATE_ERROR
Playback state of a RemoteControlClient which cannot perform any playback related
operation because of an internal error.
|
static int |
PLAYSTATE_FAST_FORWARDING
Playback state of a RemoteControlClient which is fast forwarding in the media
it is currently playing.
|
static int |
PLAYSTATE_NONE |
static int |
PLAYSTATE_PAUSED
Playback state of a RemoteControlClient which is paused.
|
static int |
PLAYSTATE_PLAYING
Playback state of a RemoteControlClient which is playing media.
|
static int |
PLAYSTATE_REWINDING
Playback state of a RemoteControlClient which is fast rewinding in the media
it is currently playing.
|
static 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.
|
static 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.
|
static int |
PLAYSTATE_STOPPED
Playback state of a RemoteControlClient which is stopped.
|
static int |
RCSE_ID_UNREGISTERED |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
RemoteControlClient.MetadataEditor |
editMetadata(boolean startEmpty)
Creates a
RemoteControlClient.MetadataEditor . |
int |
getIntPlaybackInformation(int what) |
IRemoteControlClient |
getIRemoteControlClient() |
PendingIntent |
getRcMediaIntent() |
int |
getRcseId() |
void |
setPlaybackInformation(int what,
int value) |
void |
setPlaybackState(int state)
Sets the current playback state.
|
void |
setRcseId(int id) |
void |
setTransportControlFlags(int transportControlFlags)
Sets the flags for the media transport control buttons that this client supports.
|
public static final int PLAYSTATE_STOPPED
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_PAUSED
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_PLAYING
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_FAST_FORWARDING
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_REWINDING
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_SKIPPING_FORWARDS
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_SKIPPING_BACKWARDS
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_BUFFERING
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_ERROR
setPlaybackState(int)
,
Constant Field Valuespublic static final int PLAYSTATE_NONE
public static final int PLAYBACK_TYPE_LOCAL
public static final int PLAYBACK_TYPE_REMOTE
public static final int PLAYBACK_VOLUME_FIXED
#PLAYBACKINFO_VOLUME_HANDLING.
,
Constant Field Valuespublic static final int PLAYBACK_VOLUME_VARIABLE
#PLAYBACKINFO_VOLUME_HANDLING.
,
Constant Field Valuespublic static final int PLAYBACKINFO_INVALID_VALUE
#PLAYBACKINFO_VOLUME_HANDLING.
,
Constant Field Valuespublic static final int PLAYBACKINFO_PLAYBACK_TYPE
public static final int PLAYBACKINFO_VOLUME
public static final int PLAYBACKINFO_VOLUME_MAX
public static final int PLAYBACKINFO_VOLUME_HANDLING
public static final int PLAYBACKINFO_USES_STREAM
public static final int PLAYBACKINFO_PLAYSTATE
public static final int FLAG_KEY_MEDIA_PREVIOUS
public static final int FLAG_KEY_MEDIA_REWIND
public static final int FLAG_KEY_MEDIA_PLAY
public static final int FLAG_KEY_MEDIA_PLAY_PAUSE
public static final int FLAG_KEY_MEDIA_PAUSE
public static final int FLAG_KEY_MEDIA_STOP
public static final int FLAG_KEY_MEDIA_FAST_FORWARD
public static final int FLAG_KEY_MEDIA_NEXT
public static final int FLAGS_KEY_MEDIA_NONE
public static final int FLAG_INFORMATION_REQUEST_METADATA
public static final int FLAG_INFORMATION_REQUEST_KEY_MEDIA
public static final int FLAG_INFORMATION_REQUEST_PLAYSTATE
public static final int FLAG_INFORMATION_REQUEST_ALBUM_ART
public static final int DEFAULT_PLAYBACK_VOLUME_HANDLING
public static final int DEFAULT_PLAYBACK_VOLUME
public static final int RCSE_ID_UNREGISTERED
public RemoteControlClient(PendingIntent mediaButtonIntent)
mediaButtonIntent
- The intent that will be sent for the media button events sent
by remote controls.
This intent needs to have been constructed with the Intent.ACTION_MEDIA_BUTTON
action, and have a component that will handle the intent (set with
Intent.setComponent(ComponentName)
) registered with
AudioManager.registerMediaButtonEventReceiver(ComponentName)
before this new RemoteControlClient can itself be registered with
AudioManager.registerRemoteControlClient(RemoteControlClient)
.AudioManager.registerMediaButtonEventReceiver(ComponentName)
,
AudioManager.registerRemoteControlClient(RemoteControlClient)
public RemoteControlClient(PendingIntent mediaButtonIntent, Looper looper)
mediaButtonIntent
- The intent that will be sent for the media button events sent
by remote controls.
This intent needs to have been constructed with the Intent.ACTION_MEDIA_BUTTON
action, and have a component that will handle the intent (set with
Intent.setComponent(ComponentName)
) registered with
AudioManager.registerMediaButtonEventReceiver(ComponentName)
before this new RemoteControlClient can itself be registered with
AudioManager.registerRemoteControlClient(RemoteControlClient)
.looper
- The Looper running the event loop.AudioManager.registerMediaButtonEventReceiver(ComponentName)
,
AudioManager.registerRemoteControlClient(RemoteControlClient)
public RemoteControlClient.MetadataEditor editMetadata(boolean startEmpty)
RemoteControlClient.MetadataEditor
.startEmpty
- 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.public void setPlaybackState(int state)
state
- 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
.public void setTransportControlFlags(int transportControlFlags)
transportControlFlags
- 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
public void setPlaybackInformation(int what, int value)
what
- a key to specify the type of information to set. Valid keys are
PLAYBACKINFO_PLAYBACK_TYPE
,
PLAYBACKINFO_USES_STREAM
,
PLAYBACKINFO_VOLUME
,
PLAYBACKINFO_VOLUME_MAX
,
and PLAYBACKINFO_VOLUME_HANDLING
.value
- the value for the supplied information to set.public int getIntPlaybackInformation(int what)
what
- a key to specify the type of information to retrieve. Valid keys are
PLAYBACKINFO_PLAYBACK_TYPE
,
PLAYBACKINFO_USES_STREAM
,
PLAYBACKINFO_VOLUME
,
PLAYBACKINFO_VOLUME_MAX
,
and PLAYBACKINFO_VOLUME_HANDLING
.PLAYBACKINFO_INVALID_VALUE
if an error occurred or the request is invalid, or
the value is unknown.public PendingIntent getRcMediaIntent()
public IRemoteControlClient getIRemoteControlClient()
public void setRcseId(int id)
id
- the unique identifier of the RemoteControlStackEntry in AudioService with which
this RemoteControlClient is associated.public int getRcseId()