Commit b511ed3b by samrobinson Committed by Oliver Woodman

Add more MediaMetadata fields.

Added composer, conductor and writer.

PiperOrigin-RevId: 378844760
parent 22f05e54
...@@ -54,6 +54,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -54,6 +54,9 @@ public final class MediaMetadata implements Bundleable {
@Nullable @FolderType private Integer folderType; @Nullable @FolderType private Integer folderType;
@Nullable private Boolean isPlayable; @Nullable private Boolean isPlayable;
@Nullable private Integer year; @Nullable private Integer year;
@Nullable private CharSequence writer;
@Nullable private CharSequence composer;
@Nullable private CharSequence conductor;
@Nullable private Bundle extras; @Nullable private Bundle extras;
public Builder() {} public Builder() {}
...@@ -76,6 +79,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -76,6 +79,9 @@ public final class MediaMetadata implements Bundleable {
this.folderType = mediaMetadata.folderType; this.folderType = mediaMetadata.folderType;
this.isPlayable = mediaMetadata.isPlayable; this.isPlayable = mediaMetadata.isPlayable;
this.year = mediaMetadata.year; this.year = mediaMetadata.year;
this.writer = mediaMetadata.writer;
this.composer = mediaMetadata.composer;
this.conductor = mediaMetadata.conductor;
this.extras = mediaMetadata.extras; this.extras = mediaMetadata.extras;
} }
...@@ -185,6 +191,24 @@ public final class MediaMetadata implements Bundleable { ...@@ -185,6 +191,24 @@ public final class MediaMetadata implements Bundleable {
return this; return this;
} }
/** Sets the writer. */
public Builder setWriter(@Nullable CharSequence writer) {
this.writer = writer;
return this;
}
/** Sets the composer. */
public Builder setComposer(@Nullable CharSequence composer) {
this.composer = composer;
return this;
}
/** Sets the conductor. */
public Builder setConductor(@Nullable CharSequence conductor) {
this.conductor = conductor;
return this;
}
/** Sets the extras {@link Bundle}. */ /** Sets the extras {@link Bundle}. */
public Builder setExtras(@Nullable Bundle extras) { public Builder setExtras(@Nullable Bundle extras) {
this.extras = extras; this.extras = extras;
...@@ -314,6 +338,13 @@ public final class MediaMetadata implements Bundleable { ...@@ -314,6 +338,13 @@ public final class MediaMetadata implements Bundleable {
@Nullable public final Boolean isPlayable; @Nullable public final Boolean isPlayable;
/** Optional year. */ /** Optional year. */
@Nullable public final Integer year; @Nullable public final Integer year;
/** Optional writer. */
@Nullable public final CharSequence writer;
/** Optional composer. */
@Nullable public final CharSequence composer;
/** Optional conductor. */
@Nullable public final CharSequence conductor;
/** /**
* Optional extras {@link Bundle}. * Optional extras {@link Bundle}.
* *
...@@ -340,6 +371,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -340,6 +371,9 @@ public final class MediaMetadata implements Bundleable {
this.folderType = builder.folderType; this.folderType = builder.folderType;
this.isPlayable = builder.isPlayable; this.isPlayable = builder.isPlayable;
this.year = builder.year; this.year = builder.year;
this.writer = builder.writer;
this.composer = builder.composer;
this.conductor = builder.conductor;
this.extras = builder.extras; this.extras = builder.extras;
} }
...@@ -373,7 +407,10 @@ public final class MediaMetadata implements Bundleable { ...@@ -373,7 +407,10 @@ public final class MediaMetadata implements Bundleable {
&& Util.areEqual(totalTrackCount, that.totalTrackCount) && Util.areEqual(totalTrackCount, that.totalTrackCount)
&& Util.areEqual(folderType, that.folderType) && Util.areEqual(folderType, that.folderType)
&& Util.areEqual(isPlayable, that.isPlayable) && Util.areEqual(isPlayable, that.isPlayable)
&& Util.areEqual(year, that.year); && Util.areEqual(year, that.year)
&& Util.areEqual(writer, that.writer)
&& Util.areEqual(composer, that.composer)
&& Util.areEqual(conductor, that.conductor);
} }
@Override @Override
...@@ -395,6 +432,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -395,6 +432,9 @@ public final class MediaMetadata implements Bundleable {
totalTrackCount, totalTrackCount,
folderType, folderType,
isPlayable, isPlayable,
writer,
composer,
conductor,
year); year);
} }
...@@ -420,6 +460,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -420,6 +460,9 @@ public final class MediaMetadata implements Bundleable {
FIELD_FOLDER_TYPE, FIELD_FOLDER_TYPE,
FIELD_IS_PLAYABLE, FIELD_IS_PLAYABLE,
FIELD_YEAR, FIELD_YEAR,
FIELD_WRITER,
FIELD_COMPOSER,
FIELD_CONDUCTOR,
FIELD_EXTRAS FIELD_EXTRAS
}) })
private @interface FieldNumber {} private @interface FieldNumber {}
...@@ -441,6 +484,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -441,6 +484,9 @@ public final class MediaMetadata implements Bundleable {
private static final int FIELD_FOLDER_TYPE = 14; private static final int FIELD_FOLDER_TYPE = 14;
private static final int FIELD_IS_PLAYABLE = 15; private static final int FIELD_IS_PLAYABLE = 15;
private static final int FIELD_YEAR = 16; private static final int FIELD_YEAR = 16;
private static final int FIELD_WRITER = 17;
private static final int FIELD_COMPOSER = 18;
private static final int FIELD_CONDUCTOR = 19;
private static final int FIELD_EXTRAS = 1000; private static final int FIELD_EXTRAS = 1000;
@Override @Override
...@@ -456,6 +502,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -456,6 +502,9 @@ public final class MediaMetadata implements Bundleable {
bundle.putParcelable(keyForField(FIELD_MEDIA_URI), mediaUri); bundle.putParcelable(keyForField(FIELD_MEDIA_URI), mediaUri);
bundle.putByteArray(keyForField(FIELD_ARTWORK_DATA), artworkData); bundle.putByteArray(keyForField(FIELD_ARTWORK_DATA), artworkData);
bundle.putParcelable(keyForField(FIELD_ARTWORK_URI), artworkUri); bundle.putParcelable(keyForField(FIELD_ARTWORK_URI), artworkUri);
bundle.putCharSequence(keyForField(FIELD_WRITER), writer);
bundle.putCharSequence(keyForField(FIELD_COMPOSER), composer);
bundle.putCharSequence(keyForField(FIELD_CONDUCTOR), conductor);
if (userRating != null) { if (userRating != null) {
bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle()); bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle());
...@@ -500,6 +549,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -500,6 +549,9 @@ public final class MediaMetadata implements Bundleable {
.setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI))) .setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI)))
.setArtworkData(bundle.getByteArray(keyForField(FIELD_ARTWORK_DATA))) .setArtworkData(bundle.getByteArray(keyForField(FIELD_ARTWORK_DATA)))
.setArtworkUri(bundle.getParcelable(keyForField(FIELD_ARTWORK_URI))) .setArtworkUri(bundle.getParcelable(keyForField(FIELD_ARTWORK_URI)))
.setWriter(bundle.getCharSequence(keyForField(FIELD_WRITER)))
.setComposer(bundle.getCharSequence(keyForField(FIELD_COMPOSER)))
.setConductor(bundle.getCharSequence(keyForField(FIELD_CONDUCTOR)))
.setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS))); .setExtras(bundle.getBundle(keyForField(FIELD_EXTRAS)));
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) { if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
......
...@@ -81,6 +81,18 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -81,6 +81,18 @@ public final class TextInformationFrame extends Id3Frame {
// Do nothing, invalid input. // Do nothing, invalid input.
} }
break; break;
case "TCM":
case "TCOM":
builder.setComposer(value);
break;
case "TP3":
case "TPE3":
builder.setConductor(value);
break;
case "TXT":
case "TEXT":
builder.setWriter(value);
break;
default: default:
break; break;
} }
......
...@@ -55,6 +55,9 @@ public class MediaMetadataTest { ...@@ -55,6 +55,9 @@ public class MediaMetadataTest {
assertThat(mediaMetadata.folderType).isNull(); assertThat(mediaMetadata.folderType).isNull();
assertThat(mediaMetadata.isPlayable).isNull(); assertThat(mediaMetadata.isPlayable).isNull();
assertThat(mediaMetadata.year).isNull(); assertThat(mediaMetadata.year).isNull();
assertThat(mediaMetadata.composer).isNull();
assertThat(mediaMetadata.conductor).isNull();
assertThat(mediaMetadata.writer).isNull();
assertThat(mediaMetadata.extras).isNull(); assertThat(mediaMetadata.extras).isNull();
} }
...@@ -101,6 +104,9 @@ public class MediaMetadataTest { ...@@ -101,6 +104,9 @@ public class MediaMetadataTest {
.setFolderType(MediaMetadata.FOLDER_TYPE_PLAYLISTS) .setFolderType(MediaMetadata.FOLDER_TYPE_PLAYLISTS)
.setIsPlayable(true) .setIsPlayable(true)
.setYear(2000) .setYear(2000)
.setComposer("Composer")
.setConductor("Conductor")
.setWriter("Writer")
.setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o). .setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o).
.build(); .build();
...@@ -117,6 +123,9 @@ public class MediaMetadataTest { ...@@ -117,6 +123,9 @@ public class MediaMetadataTest {
String albumArtist = "album Artist"; String albumArtist = "album Artist";
String trackNumberInfo = "11/17"; String trackNumberInfo = "11/17";
String year = "2000"; String year = "2000";
String composer = "composer";
String conductor = "conductor";
String writer = "writer";
List<Metadata.Entry> entries = List<Metadata.Entry> entries =
ImmutableList.of( ImmutableList.of(
...@@ -128,20 +137,31 @@ public class MediaMetadataTest { ...@@ -128,20 +137,31 @@ public class MediaMetadataTest {
/* id= */ "TP2", /* description= */ null, /* value= */ albumArtist), /* id= */ "TP2", /* description= */ null, /* value= */ albumArtist),
new TextInformationFrame( new TextInformationFrame(
/* id= */ "TRK", /* description= */ null, /* value= */ trackNumberInfo), /* id= */ "TRK", /* description= */ null, /* value= */ trackNumberInfo),
new TextInformationFrame(/* id= */ "TYE", /* description= */ null, /* value= */ year)); new TextInformationFrame(/* id= */ "TYE", /* description= */ null, /* value= */ year),
new TextInformationFrame(
/* id= */ "TCM", /* description= */ null, /* value= */ composer),
new TextInformationFrame(
/* id= */ "TP3", /* description= */ null, /* value= */ conductor),
new TextInformationFrame(
/* id= */ "TXT", /* description= */ null, /* value= */ writer));
MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon(); MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
for (Metadata.Entry entry : entries) { for (Metadata.Entry entry : entries) {
entry.populateMediaMetadata(builder); entry.populateMediaMetadata(builder);
} }
assertThat(builder.build().title.toString()).isEqualTo(title); MediaMetadata mediaMetadata = builder.build();
assertThat(builder.build().artist.toString()).isEqualTo(artist);
assertThat(builder.build().albumTitle.toString()).isEqualTo(albumTitle); assertThat(mediaMetadata.title.toString()).isEqualTo(title);
assertThat(builder.build().albumArtist.toString()).isEqualTo(albumArtist); assertThat(mediaMetadata.artist.toString()).isEqualTo(artist);
assertThat(builder.build().trackNumber).isEqualTo(11); assertThat(mediaMetadata.albumTitle.toString()).isEqualTo(albumTitle);
assertThat(builder.build().totalTrackCount).isEqualTo(17); assertThat(mediaMetadata.albumArtist.toString()).isEqualTo(albumArtist);
assertThat(builder.build().year).isEqualTo(2000); assertThat(mediaMetadata.trackNumber).isEqualTo(11);
assertThat(mediaMetadata.totalTrackCount).isEqualTo(17);
assertThat(mediaMetadata.year).isEqualTo(2000);
assertThat(mediaMetadata.composer.toString()).isEqualTo(composer);
assertThat(mediaMetadata.conductor.toString()).isEqualTo(conductor);
assertThat(mediaMetadata.writer.toString()).isEqualTo(writer);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment