Skip to content

Commit

Permalink
Include mediaId when marshalling a MediaItem to JSON
Browse files Browse the repository at this point in the history
When sending a MediaItem to a MediaSession with a Media3 MediaController important information is removed for privacy reason. To look up the fully populated MediaItem the mediaId is used as a key. Hence having the mediaId marhalled to the JSON representation that is sent to a Cast device enables app developers to use the same look up facilities.

#minor-release

PiperOrigin-RevId: 420022868
  • Loading branch information
marcbaechinger authored and ojw28 committed Jan 7, 2022
1 parent 9dbace1 commit a8e4429
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public final class DefaultMediaItemConverter implements MediaItemConverter {

private static final String KEY_MEDIA_ITEM = "mediaItem";
private static final String KEY_PLAYER_CONFIG = "exoPlayerConfig";
private static final String KEY_MEDIA_ID = "mediaId";
private static final String KEY_URI = "uri";
private static final String KEY_TITLE = "title";
private static final String KEY_MIME_TYPE = "mimeType";
Expand Down Expand Up @@ -77,6 +78,7 @@ private static MediaItem getMediaItem(JSONObject customData) {
JSONObject mediaItemJson = customData.getJSONObject(KEY_MEDIA_ITEM);
MediaItem.Builder builder = new MediaItem.Builder();
builder.setUri(Uri.parse(mediaItemJson.getString(KEY_URI)));
builder.setMediaId(mediaItemJson.getString(KEY_MEDIA_ID));
if (mediaItemJson.has(KEY_TITLE)) {
com.google.android.exoplayer2.MediaMetadata mediaMetadata =
new com.google.android.exoplayer2.MediaMetadata.Builder()
Expand Down Expand Up @@ -130,6 +132,7 @@ private static JSONObject getCustomData(MediaItem mediaItem) {
private static JSONObject getMediaItemJson(MediaItem mediaItem) throws JSONException {
Assertions.checkNotNull(mediaItem.localConfiguration);
JSONObject json = new JSONObject();
json.put(KEY_MEDIA_ID, mediaItem.mediaId);
json.put(KEY_TITLE, mediaItem.mediaMetadata.title);
json.put(KEY_URI, mediaItem.localConfiguration.uri.toString());
json.put(KEY_MIME_TYPE, mediaItem.localConfiguration.mimeType);
Expand Down

0 comments on commit a8e4429

Please sign in to comment.