From 259f0f67a30fe6fa32aafdc94eee547eeed66748 Mon Sep 17 00:00:00 2001 From: samrobinson Date: Thu, 17 Jun 2021 19:05:42 +0100 Subject: [PATCH] Add genre to MediaMetadata. PiperOrigin-RevId: 380000589 --- .../android/exoplayer2/MediaMetadata.java | 21 +++++++++++++++++-- .../android/exoplayer2/MediaMetadataTest.java | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java b/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java index 3852255c90..8a5c50f125 100644 --- a/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java +++ b/library/common/src/main/java/com/google/android/exoplayer2/MediaMetadata.java @@ -67,6 +67,7 @@ public final class MediaMetadata implements Bundleable { @Nullable private CharSequence conductor; @Nullable private Integer discNumber; @Nullable private Integer totalDiscCount; + @Nullable private CharSequence genre; @Nullable private Bundle extras; public Builder() {} @@ -99,6 +100,7 @@ public final class MediaMetadata implements Bundleable { this.conductor = mediaMetadata.conductor; this.discNumber = mediaMetadata.discNumber; this.totalDiscCount = mediaMetadata.totalDiscCount; + this.genre = mediaMetadata.genre; this.extras = mediaMetadata.extras; } @@ -303,6 +305,12 @@ public final class MediaMetadata implements Bundleable { return this; } + /** Sets the genre. */ + public Builder setGenre(@Nullable CharSequence genre) { + this.genre = genre; + return this; + } + /** Sets the extras {@link Bundle}. */ public Builder setExtras(@Nullable Bundle extras) { this.extras = extras; @@ -471,6 +479,8 @@ public final class MediaMetadata implements Bundleable { @Nullable public final Integer discNumber; /** Optional total number of discs. */ @Nullable public final Integer totalDiscCount; + /** Optional genre. */ + @Nullable public final CharSequence genre; /** * Optional extras {@link Bundle}. @@ -509,6 +519,7 @@ public final class MediaMetadata implements Bundleable { this.conductor = builder.conductor; this.discNumber = builder.discNumber; this.totalDiscCount = builder.totalDiscCount; + this.genre = builder.genre; this.extras = builder.extras; } @@ -552,7 +563,8 @@ public final class MediaMetadata implements Bundleable { && Util.areEqual(composer, that.composer) && Util.areEqual(conductor, that.conductor) && Util.areEqual(discNumber, that.discNumber) - && Util.areEqual(totalDiscCount, that.totalDiscCount); + && Util.areEqual(totalDiscCount, that.totalDiscCount) + && Util.areEqual(genre, that.genre); } @Override @@ -584,7 +596,8 @@ public final class MediaMetadata implements Bundleable { composer, conductor, discNumber, - totalDiscCount); + totalDiscCount, + genre); } // Bundleable implementation. @@ -619,6 +632,7 @@ public final class MediaMetadata implements Bundleable { FIELD_CONDUCTOR, FIELD_DISC_NUMBER, FIELD_TOTAL_DISC_COUNT, + FIELD_GENRE, FIELD_EXTRAS }) private @interface FieldNumber {} @@ -650,6 +664,7 @@ public final class MediaMetadata implements Bundleable { private static final int FIELD_CONDUCTOR = 24; private static final int FIELD_DISC_NUMBER = 25; private static final int FIELD_TOTAL_DISC_COUNT = 26; + private static final int FIELD_GENRE = 27; private static final int FIELD_EXTRAS = 1000; @Override @@ -668,6 +683,7 @@ public final class MediaMetadata implements Bundleable { bundle.putCharSequence(keyForField(FIELD_WRITER), writer); bundle.putCharSequence(keyForField(FIELD_COMPOSER), composer); bundle.putCharSequence(keyForField(FIELD_CONDUCTOR), conductor); + bundle.putCharSequence(keyForField(FIELD_GENRE), genre); if (userRating != null) { bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle()); @@ -736,6 +752,7 @@ public final class MediaMetadata implements Bundleable { .setWriter(bundle.getCharSequence(keyForField(FIELD_WRITER))) .setComposer(bundle.getCharSequence(keyForField(FIELD_COMPOSER))) .setConductor(bundle.getCharSequence(keyForField(FIELD_CONDUCTOR))) + .setGenre(bundle.getCharSequence(keyForField(FIELD_GENRE))) .setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS))); if (bundle.containsKey(keyForField(FIELD_USER_RATING))) { diff --git a/library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java b/library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java index 02f858a7bc..5149687402 100644 --- a/library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java +++ b/library/common/src/test/java/com/google/android/exoplayer2/MediaMetadataTest.java @@ -65,6 +65,7 @@ public class MediaMetadataTest { assertThat(mediaMetadata.writer).isNull(); assertThat(mediaMetadata.discNumber).isNull(); assertThat(mediaMetadata.totalDiscCount).isNull(); + assertThat(mediaMetadata.genre).isNull(); assertThat(mediaMetadata.extras).isNull(); } @@ -121,6 +122,7 @@ public class MediaMetadataTest { .setWriter("Writer") .setDiscNumber(1) .setTotalDiscCount(3) + .setGenre("Pop") .setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o). .build();