Add an extras bundle to MediaMetadata.
#minor-release PiperOrigin-RevId: 375435339
This commit is contained in:
parent
1fa61feb7e
commit
8d550bf05b
@ -53,6 +53,7 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Nullable private Integer totalTrackCount;
|
||||
@Nullable @FolderType private Integer folderType;
|
||||
@Nullable private Boolean isPlayable;
|
||||
@Nullable private Bundle extras;
|
||||
|
||||
public Builder() {}
|
||||
|
||||
@ -73,6 +74,7 @@ public final class MediaMetadata implements Bundleable {
|
||||
this.totalTrackCount = mediaMetadata.totalTrackCount;
|
||||
this.folderType = mediaMetadata.folderType;
|
||||
this.isPlayable = mediaMetadata.isPlayable;
|
||||
this.extras = mediaMetadata.extras;
|
||||
}
|
||||
|
||||
/** Sets the title. */
|
||||
@ -175,6 +177,12 @@ public final class MediaMetadata implements Bundleable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the extras {@link Bundle}. */
|
||||
public Builder setExtras(@Nullable Bundle extras) {
|
||||
this.extras = extras;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}.
|
||||
*
|
||||
@ -293,6 +301,13 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Nullable @FolderType public final Integer folderType;
|
||||
/** Optional boolean for media playability. */
|
||||
@Nullable public final Boolean isPlayable;
|
||||
/**
|
||||
* Optional extras {@link Bundle}.
|
||||
*
|
||||
* <p>Given the complexities of checking the equality of two {@link Bundle}s, this is not
|
||||
* considered in the {@link #equals(Object)} or {@link #hashCode()}.
|
||||
*/
|
||||
@Nullable public final Bundle extras;
|
||||
|
||||
private MediaMetadata(Builder builder) {
|
||||
this.title = builder.title;
|
||||
@ -311,6 +326,7 @@ public final class MediaMetadata implements Bundleable {
|
||||
this.totalTrackCount = builder.totalTrackCount;
|
||||
this.folderType = builder.folderType;
|
||||
this.isPlayable = builder.isPlayable;
|
||||
this.extras = builder.extras;
|
||||
}
|
||||
|
||||
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
|
||||
@ -386,7 +402,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
FIELD_TRACK_NUMBER,
|
||||
FIELD_TOTAL_TRACK_COUNT,
|
||||
FIELD_FOLDER_TYPE,
|
||||
FIELD_IS_PLAYABLE
|
||||
FIELD_IS_PLAYABLE,
|
||||
FIELD_EXTRAS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
@ -406,6 +423,7 @@ public final class MediaMetadata implements Bundleable {
|
||||
private static final int FIELD_TOTAL_TRACK_COUNT = 13;
|
||||
private static final int FIELD_FOLDER_TYPE = 14;
|
||||
private static final int FIELD_IS_PLAYABLE = 15;
|
||||
private static final int FIELD_EXTRAS = 1000;
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
@ -439,7 +457,9 @@ public final class MediaMetadata implements Bundleable {
|
||||
if (isPlayable != null) {
|
||||
bundle.putBoolean(keyForField(FIELD_IS_PLAYABLE), isPlayable);
|
||||
}
|
||||
|
||||
if (extras != null) {
|
||||
bundle.putBundle(keyForField(FIELD_EXTRAS), extras);
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@ -458,7 +478,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
.setDescription(bundle.getCharSequence(keyForField(FIELD_DESCRIPTION)))
|
||||
.setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI)))
|
||||
.setArtworkData(bundle.getByteArray(keyForField(FIELD_ARTWORK_DATA)))
|
||||
.setArtworkUri(bundle.getParcelable(keyForField(FIELD_ARTWORK_URI)));
|
||||
.setArtworkUri(bundle.getParcelable(keyForField(FIELD_ARTWORK_URI)))
|
||||
.setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS)));
|
||||
|
||||
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(keyForField(FIELD_USER_RATING));
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.id3.ApicFrame;
|
||||
@ -49,8 +50,11 @@ public class MediaMetadataTest {
|
||||
assertThat(mediaMetadata.overallRating).isNull();
|
||||
assertThat(mediaMetadata.artworkData).isNull();
|
||||
assertThat(mediaMetadata.artworkUri).isNull();
|
||||
assertThat(mediaMetadata.trackNumber).isNull();
|
||||
assertThat(mediaMetadata.totalTrackCount).isNull();
|
||||
assertThat(mediaMetadata.folderType).isNull();
|
||||
assertThat(mediaMetadata.isPlayable).isNull();
|
||||
assertThat(mediaMetadata.extras).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -80,6 +84,9 @@ public class MediaMetadataTest {
|
||||
|
||||
@Test
|
||||
public void roundTripViaBundle_yieldsEqualInstance() {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putString("exampleKey", "exampleValue");
|
||||
|
||||
MediaMetadata mediaMetadata =
|
||||
new MediaMetadata.Builder()
|
||||
.setTitle("title")
|
||||
@ -88,12 +95,16 @@ public class MediaMetadataTest {
|
||||
.setUserRating(new HeartRating(false))
|
||||
.setOverallRating(new PercentageRating(87.4f))
|
||||
.setArtworkData(new byte[] {-88, 12, 3, 2, 124, -54, -33, 69})
|
||||
.setTrackNumber(4)
|
||||
.setTotalTrackCount(12)
|
||||
.setFolderType(MediaMetadata.FOLDER_TYPE_PLAYLISTS)
|
||||
.setIsPlayable(true)
|
||||
.setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o).
|
||||
.build();
|
||||
|
||||
MediaMetadata fromBundle = MediaMetadata.CREATOR.fromBundle(mediaMetadata.toBundle());
|
||||
assertThat(fromBundle).isEqualTo(mediaMetadata);
|
||||
assertThat(fromBundle.extras.getString("exampleKey")).isEqualTo("exampleValue");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user