Skip to content

Commit 466ade5

Browse files
committed
Fix bug 5045498 Unhide Remote Control Client API
The RemoteControlClient API enables media application to have information such as album art, current song, playback state be displayed on "remote control displays", as well as be controlled by "remote controls". The new API consists in: - a new class, RemoteControlClient - new methods in AudioManager to register a RemoteControlClient - a new class, RemoteControlClient.MetadataEditor to edit and apply the information associated with a RemoteControlClient, and which will be displayed on a "remote control display" Change-Id: I5616085e4ad58ce0bbc1a5953b0a5a28d32f8703
1 parent a6ec356 commit 466ade5

File tree

3 files changed

+116
-47
lines changed

3 files changed

+116
-47
lines changed

api/current.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10284,6 +10284,7 @@ package android.media {
1028410284
method public void playSoundEffect(int);
1028510285
method public void playSoundEffect(int, float);
1028610286
method public void registerMediaButtonEventReceiver(android.content.ComponentName);
10287+
method public void registerRemoteControlClient(android.media.RemoteControlClient);
1028710288
method public int requestAudioFocus(android.media.AudioManager.OnAudioFocusChangeListener, int, int);
1028810289
method public deprecated void setBluetoothA2dpOn(boolean);
1028910290
method public void setBluetoothScoOn(boolean);
@@ -10303,6 +10304,7 @@ package android.media {
1030310304
method public void stopBluetoothSco();
1030410305
method public void unloadSoundEffects();
1030510306
method public void unregisterMediaButtonEventReceiver(android.content.ComponentName);
10307+
method public void unregisterRemoteControlClient(android.media.RemoteControlClient);
1030610308
field public static final java.lang.String ACTION_AUDIO_BECOMING_NOISY = "android.media.AUDIO_BECOMING_NOISY";
1030710309
field public static final deprecated java.lang.String ACTION_SCO_AUDIO_STATE_CHANGED = "android.media.SCO_AUDIO_STATE_CHANGED";
1030810310
field public static final java.lang.String ACTION_SCO_AUDIO_STATE_UPDATED = "android.media.ACTION_SCO_AUDIO_STATE_UPDATED";
@@ -10844,6 +10846,40 @@ package android.media {
1084410846
field public static final int SEEK_FORWARD_AVAILABLE = 3; // 0x3
1084510847
}
1084610848

10849+
public class RemoteControlClient {
10850+
ctor public RemoteControlClient(android.content.ComponentName);
10851+
ctor public RemoteControlClient(android.content.ComponentName, android.os.Looper);
10852+
method public android.media.RemoteControlClient.MetadataEditor editMetadata(boolean);
10853+
method public void setPlaybackState(int);
10854+
method public void setTransportControlFlags(int);
10855+
field public static final int FLAG_KEY_MEDIA_FAST_FORWARD = 64; // 0x40
10856+
field public static final int FLAG_KEY_MEDIA_NEXT = 128; // 0x80
10857+
field public static final int FLAG_KEY_MEDIA_PAUSE = 16; // 0x10
10858+
field public static final int FLAG_KEY_MEDIA_PLAY = 4; // 0x4
10859+
field public static final int FLAG_KEY_MEDIA_PLAY_PAUSE = 8; // 0x8
10860+
field public static final int FLAG_KEY_MEDIA_PREVIOUS = 1; // 0x1
10861+
field public static final int FLAG_KEY_MEDIA_REWIND = 2; // 0x2
10862+
field public static final int FLAG_KEY_MEDIA_STOP = 32; // 0x20
10863+
field public static final int PLAYSTATE_BUFFERING = 8; // 0x8
10864+
field public static final int PLAYSTATE_ERROR = 9; // 0x9
10865+
field public static final int PLAYSTATE_FAST_FORWARDING = 4; // 0x4
10866+
field public static final int PLAYSTATE_PAUSED = 2; // 0x2
10867+
field public static final int PLAYSTATE_PLAYING = 3; // 0x3
10868+
field public static final int PLAYSTATE_REWINDING = 5; // 0x5
10869+
field public static final int PLAYSTATE_SKIPPING_BACKWARDS = 7; // 0x7
10870+
field public static final int PLAYSTATE_SKIPPING_FORWARDS = 6; // 0x6
10871+
field public static final int PLAYSTATE_STOPPED = 1; // 0x1
10872+
}
10873+
10874+
public class RemoteControlClient.MetadataEditor {
10875+
method public synchronized void apply();
10876+
method public synchronized void clear();
10877+
method public synchronized android.media.RemoteControlClient.MetadataEditor putBitmap(int, android.graphics.Bitmap) throws java.lang.IllegalArgumentException;
10878+
method public synchronized android.media.RemoteControlClient.MetadataEditor putLong(int, long) throws java.lang.IllegalArgumentException;
10879+
method public synchronized android.media.RemoteControlClient.MetadataEditor putString(int, java.lang.String) throws java.lang.IllegalArgumentException;
10880+
field public static final int BITMAP_KEY_ARTWORK = 100; // 0x64
10881+
}
10882+
1084710883
public class Ringtone {
1084810884
method public int getStreamType();
1084910885
method public java.lang.String getTitle(android.content.Context);

media/java/android/media/AudioManager.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,12 +1717,11 @@ public void unregisterMediaButtonEventReceiver(ComponentName eventReceiver) {
17171717

17181718

17191719
/**
1720-
* @hide
1721-
* CANDIDATE FOR SDK
17221720
* Registers the remote control client for providing information to display on the remote
17231721
* controls.
1724-
* @param rcClient the remote control client associated responsible
1725-
* for providing the information to display on the remote control.
1722+
* @param rcClient The remote control client from which remote controls will receive
1723+
* information to display.
1724+
* @see RemoteControlClient
17261725
*/
17271726
public void registerRemoteControlClient(RemoteControlClient rcClient) {
17281727
if ((rcClient == null) || (rcClient.getRcEventReceiver() == null)) {
@@ -1741,11 +1740,9 @@ public void registerRemoteControlClient(RemoteControlClient rcClient) {
17411740
}
17421741

17431742
/**
1744-
* @hide
1745-
* CANDIDATE FOR SDK
17461743
* Unregisters the remote control client that was providing information to display on the
1747-
* remotes.
1748-
* @param rcClient the remote control client to unregister
1744+
* remote controls.
1745+
* @param rcClient The remote control client to unregister.
17491746
* @see #registerRemoteControlClient(RemoteControlClient)
17501747
*/
17511748
public void unregisterRemoteControlClient(RemoteControlClient rcClient) {

media/java/android/media/RemoteControlClient.java

Lines changed: 75 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package android.media;
1818

1919
import android.content.ComponentName;
20-
import android.content.SharedPreferences.Editor;
2120
import android.graphics.Bitmap;
2221
import android.graphics.Canvas;
2322
import android.graphics.Paint;
@@ -31,15 +30,14 @@
3130
import android.util.Log;
3231

3332
import java.lang.IllegalArgumentException;
34-
import java.util.HashMap;
3533

3634
/**
37-
* @hide
38-
* CANDIDATE FOR SDK
3935
* RemoteControlClient enables exposing information meant to be consumed by remote controls
40-
* capable of displaying metadata, album art and media transport control buttons.
41-
* A remote control client object is associated with a media button event receiver
42-
* when registered through
36+
* capable of displaying metadata, artwork and media transport control buttons.
37+
* A remote control client object is associated with a media button event receiver. This
38+
* event receiver must have been previously registered with
39+
* {@link AudioManager#registerMediaButtonEventReceiver(ComponentName)} before the
40+
* RemoteControlClient can be registered through
4341
* {@link AudioManager#registerRemoteControlClient(RemoteControlClient)}.
4442
*/
4543
public class RemoteControlClient
@@ -110,7 +108,8 @@ public class RemoteControlClient
110108
public final static int PLAYSTATE_ERROR = 9;
111109
/**
112110
* @hide
113-
* The value of a playback state when none has been declared
111+
* The value of a playback state when none has been declared.
112+
* Intentionally hidden as an application shouldn't set such a playback state value.
114113
*/
115114
public final static int PLAYSTATE_NONE = 0;
116115

@@ -122,7 +121,7 @@ public class RemoteControlClient
122121
*/
123122
public final static int FLAG_KEY_MEDIA_PREVIOUS = 1 << 0;
124123
/**
125-
* Flag indicating a RemoteControlClient makes use of the "rewing" media key.
124+
* Flag indicating a RemoteControlClient makes use of the "rewind" media key.
126125
*
127126
* @see #setTransportControlFlags(int)
128127
* @see android.view.KeyEvent#KEYCODE_MEDIA_REWIND
@@ -173,7 +172,9 @@ public class RemoteControlClient
173172

174173
/**
175174
* @hide
176-
* The flags for when no media keys are declared supported
175+
* The flags for when no media keys are declared supported.
176+
* Intentionally hidden as an application shouldn't set the transport control flags
177+
* to this value.
177178
*/
178179
public final static int FLAGS_KEY_MEDIA_NONE = 0;
179180

@@ -184,29 +185,29 @@ public class RemoteControlClient
184185
public final static int FLAG_INFORMATION_REQUEST_METADATA = 1 << 0;
185186
/**
186187
* @hide
187-
* FIXME doc not valid
188188
* Flag used to signal that the transport control buttons supported by the
189-
* RemoteControlClient have changed.
189+
* RemoteControlClient are requested.
190190
* This can for instance happen when playback is at the end of a playlist, and the "next"
191191
* operation is not supported anymore.
192192
*/
193193
public final static int FLAG_INFORMATION_REQUEST_KEY_MEDIA = 1 << 1;
194194
/**
195195
* @hide
196-
* FIXME doc not valid
197-
* Flag used to signal that the playback state of the RemoteControlClient has changed.
196+
* Flag used to signal that the playback state of the RemoteControlClient is requested.
198197
*/
199198
public final static int FLAG_INFORMATION_REQUEST_PLAYSTATE = 1 << 2;
200199
/**
201200
* @hide
202-
* FIXME doc not valid
203-
* Flag used to signal that the album art for the RemoteControlClient has changed.
201+
* Flag used to signal that the album art for the RemoteControlClient is requested.
204202
*/
205203
public final static int FLAG_INFORMATION_REQUEST_ALBUM_ART = 1 << 3;
206204

207205
/**
208206
* Class constructor.
209-
* @param mediaButtonEventReceiver the receiver for the media button events.
207+
* @param mediaButtonEventReceiver The receiver for the media button events. It needs to have
208+
* been registered with {@link AudioManager#registerMediaButtonEventReceiver(ComponentName)}
209+
* before this new RemoteControlClient can itself be registered with
210+
* {@link AudioManager#registerRemoteControlClient(RemoteControlClient)}.
210211
* @see AudioManager#registerMediaButtonEventReceiver(ComponentName)
211212
* @see AudioManager#registerRemoteControlClient(RemoteControlClient)
212213
*/
@@ -227,8 +228,11 @@ public RemoteControlClient(ComponentName mediaButtonEventReceiver) {
227228
/**
228229
* Class constructor for a remote control client whose internal event handling
229230
* happens on a user-provided Looper.
230-
* @param mediaButtonEventReceiver the receiver for the media button events.
231-
* @param looper the Looper running the event loop.
231+
* @param mediaButtonEventReceiver The receiver for the media button events. It needs to have
232+
* been registered with {@link AudioManager#registerMediaButtonEventReceiver(ComponentName)}
233+
* before this new RemoteControlClient can itself be registered with
234+
* {@link AudioManager#registerRemoteControlClient(RemoteControlClient)}.
235+
* @param looper The Looper running the event loop.
232236
* @see AudioManager#registerMediaButtonEventReceiver(ComponentName)
233237
* @see AudioManager#registerRemoteControlClient(RemoteControlClient)
234238
*/
@@ -257,11 +261,28 @@ public RemoteControlClient(ComponentName mediaButtonEventReceiver, Looper looper
257261

258262
/**
259263
* Class used to modify metadata in a {@link RemoteControlClient} object.
264+
* Use {@link RemoteControlClient#editMetadata(boolean)} to create an instance of an editor,
265+
* on which you set the metadata for the RemoteControlClient instance. Once all the information
266+
* has been set, use {@link #apply()} to make it the new metadata that should be displayed
267+
* for the associated client. Once the metadata has been "applied", you cannot reuse this
268+
* instance of the MetadataEditor.
260269
*/
261270
public class MetadataEditor {
271+
/**
272+
* @hide
273+
*/
262274
protected boolean mMetadataChanged;
275+
/**
276+
* @hide
277+
*/
263278
protected boolean mArtworkChanged;
279+
/**
280+
* @hide
281+
*/
264282
protected Bitmap mEditorArtwork;
283+
/**
284+
* @hide
285+
*/
265286
protected Bundle mEditorMetadata;
266287
private boolean mApplied = false;
267288

@@ -277,13 +298,18 @@ public Object clone() throws CloneNotSupportedException {
277298
/**
278299
* The metadata key for the content artwork / album art.
279300
*/
280-
public final static int METADATA_KEY_ARTWORK = 100;
301+
public final static int BITMAP_KEY_ARTWORK = 100;
302+
/**
303+
* @hide
304+
* TODO(jmtrivi) have lockscreen and music move to the new key name
305+
*/
306+
public final static int METADATA_KEY_ARTWORK = BITMAP_KEY_ARTWORK;
281307

282308
/**
283309
* Adds textual information to be displayed.
284310
* Note that none of the information added after {@link #apply()} has been called,
285311
* will be displayed.
286-
* @param key the identifier of a the metadata field to set. Valid values are
312+
* @param key The identifier of a the metadata field to set. Valid values are
287313
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_ALBUM},
288314
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_ALBUMARTIST},
289315
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_TITLE},
@@ -294,11 +320,11 @@ public Object clone() throws CloneNotSupportedException {
294320
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DATE},
295321
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_GENRE},
296322
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_TITLE},
297-
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_WRITER},
298-
* .
299-
* @param value the text for the given key, or {@code null} to signify there is no valid
323+
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_WRITER}.
324+
* @param value The text for the given key, or {@code null} to signify there is no valid
300325
* information for the field.
301-
* @return FIXME description
326+
* @return Returns a reference to the same MetadataEditor object, so you can chain put
327+
* calls together.
302328
*/
303329
public synchronized MetadataEditor putString(int key, String value)
304330
throws IllegalArgumentException {
@@ -315,15 +341,18 @@ public synchronized MetadataEditor putString(int key, String value)
315341
}
316342

317343
/**
318-
* FIXME javadoc
344+
* Adds numerical information to be displayed.
345+
* Note that none of the information added after {@link #apply()} has been called,
346+
* will be displayed.
319347
* @param key the identifier of a the metadata field to set. Valid values are
320348
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_CD_TRACK_NUMBER},
321349
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DISC_NUMBER},
322350
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DURATION} (with a value
323351
* expressed in milliseconds),
324352
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_YEAR}.
325-
* @param value FIXME javadoc
326-
* @return FIXME javadoc
353+
* @param value The long value for the given key
354+
* @return Returns a reference to the same MetadataEditor object, so you can chain put
355+
* calls together.
327356
* @throws IllegalArgumentException
328357
*/
329358
public synchronized MetadataEditor putLong(int key, long value)
@@ -342,9 +371,11 @@ public synchronized MetadataEditor putLong(int key, long value)
342371

343372
/**
344373
* Sets the album / artwork picture to be displayed on the remote control.
345-
* @param key FIXME description
346-
* @param bitmap the bitmap for the artwork, or null if there isn't any.
347-
* @return FIXME description
374+
* @param key the identifier of the bitmap to set. The only valid value is
375+
* {@link #BITMAP_KEY_ARTWORK}
376+
* @param bitmap The bitmap for the artwork, or null if there isn't any.
377+
* @return Returns a reference to the same MetadataEditor object, so you can chain put
378+
* calls together.
348379
* @throws IllegalArgumentException
349380
* @see android.graphics.Bitmap
350381
*/
@@ -354,7 +385,7 @@ public synchronized MetadataEditor putBitmap(int key, Bitmap bitmap)
354385
Log.e(TAG, "Can't edit a previously applied MetadataEditor");
355386
return this;
356387
}
357-
if (key != METADATA_KEY_ARTWORK) {
388+
if (key != BITMAP_KEY_ARTWORK) {
358389
throw(new IllegalArgumentException("Invalid type 'Bitmap' for key "+ key));
359390
}
360391
if ((mArtworkExpectedWidth > 0) && (mArtworkExpectedHeight > 0)) {
@@ -369,7 +400,8 @@ public synchronized MetadataEditor putBitmap(int key, Bitmap bitmap)
369400
}
370401

371402
/**
372-
* FIXME description
403+
* Clears all the metadata that has been set since the MetadataEditor instance was
404+
* created with {@link RemoteControlClient#editMetadata(boolean)}.
373405
*/
374406
public synchronized void clear() {
375407
if (mApplied) {
@@ -381,7 +413,10 @@ public synchronized void clear() {
381413
}
382414

383415
/**
384-
* FIXME description
416+
* Associates all the metadata that has been set since the MetadataEditor instance was
417+
* created with {@link RemoteControlClient#editMetadata(boolean)}, or since
418+
* {@link #clear()} was called, with the RemoteControlClient. Once "applied",
419+
* this MetadataEditor cannot be reused to edit the RemoteControlClient's metadata.
385420
*/
386421
public synchronized void apply() {
387422
if (mApplied) {
@@ -408,9 +443,10 @@ public synchronized void apply() {
408443
}
409444

410445
/**
411-
* FIXME description
412-
* @param startEmpty
413-
* @return
446+
* Creates a {@link MetadataEditor}.
447+
* @param startEmpty Set to false if you want the MetadataEditor to contain the metadata that
448+
* was previously applied to the RemoteControlClient, or true if it is to be created empty.
449+
* @return a new MetadataEditor instance.
414450
*/
415451
public MetadataEditor editMetadata(boolean startEmpty) {
416452
MetadataEditor editor = new MetadataEditor();
@@ -430,7 +466,7 @@ public MetadataEditor editMetadata(boolean startEmpty) {
430466

431467
/**
432468
* Sets the current playback state.
433-
* @param state the current playback state, one of the following values:
469+
* @param state The current playback state, one of the following values:
434470
* {@link #PLAYSTATE_STOPPED},
435471
* {@link #PLAYSTATE_PAUSED},
436472
* {@link #PLAYSTATE_PLAYING},
@@ -453,7 +489,7 @@ public void setPlaybackState(int state) {
453489

454490
/**
455491
* Sets the flags for the media transport control buttons that this client supports.
456-
* @param a combination of the following flags:
492+
* @param transportControlFlags A combination of the following flags:
457493
* {@link #FLAG_KEY_MEDIA_PREVIOUS},
458494
* {@link #FLAG_KEY_MEDIA_REWIND},
459495
* {@link #FLAG_KEY_MEDIA_PLAY},

0 commit comments

Comments
 (0)