mirror of
https://github.com/samsonjs/media.git
synced 2026-04-19 13:35:47 +00:00
Add more MediaMetadata fields.
Added composer, conductor and writer. PiperOrigin-RevId: 378844760
This commit is contained in:
parent
22f05e549a
commit
b511ed3b37
3 changed files with 93 additions and 9 deletions
|
|
@ -54,6 +54,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable @FolderType private Integer folderType;
|
||||
@Nullable private Boolean isPlayable;
|
||||
@Nullable private Integer year;
|
||||
@Nullable private CharSequence writer;
|
||||
@Nullable private CharSequence composer;
|
||||
@Nullable private CharSequence conductor;
|
||||
@Nullable private Bundle extras;
|
||||
|
||||
public Builder() {}
|
||||
|
|
@ -76,6 +79,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.folderType = mediaMetadata.folderType;
|
||||
this.isPlayable = mediaMetadata.isPlayable;
|
||||
this.year = mediaMetadata.year;
|
||||
this.writer = mediaMetadata.writer;
|
||||
this.composer = mediaMetadata.composer;
|
||||
this.conductor = mediaMetadata.conductor;
|
||||
this.extras = mediaMetadata.extras;
|
||||
}
|
||||
|
||||
|
|
@ -185,6 +191,24 @@ public final class MediaMetadata implements Bundleable {
|
|||
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}. */
|
||||
public Builder setExtras(@Nullable Bundle extras) {
|
||||
this.extras = extras;
|
||||
|
|
@ -314,6 +338,13 @@ public final class MediaMetadata implements Bundleable {
|
|||
@Nullable public final Boolean isPlayable;
|
||||
/** Optional 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}.
|
||||
*
|
||||
|
|
@ -340,6 +371,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
this.folderType = builder.folderType;
|
||||
this.isPlayable = builder.isPlayable;
|
||||
this.year = builder.year;
|
||||
this.writer = builder.writer;
|
||||
this.composer = builder.composer;
|
||||
this.conductor = builder.conductor;
|
||||
this.extras = builder.extras;
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +407,10 @@ public final class MediaMetadata implements Bundleable {
|
|||
&& Util.areEqual(totalTrackCount, that.totalTrackCount)
|
||||
&& Util.areEqual(folderType, that.folderType)
|
||||
&& 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
|
||||
|
|
@ -395,6 +432,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
totalTrackCount,
|
||||
folderType,
|
||||
isPlayable,
|
||||
writer,
|
||||
composer,
|
||||
conductor,
|
||||
year);
|
||||
}
|
||||
|
||||
|
|
@ -420,6 +460,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
FIELD_FOLDER_TYPE,
|
||||
FIELD_IS_PLAYABLE,
|
||||
FIELD_YEAR,
|
||||
FIELD_WRITER,
|
||||
FIELD_COMPOSER,
|
||||
FIELD_CONDUCTOR,
|
||||
FIELD_EXTRAS
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
|
@ -441,6 +484,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
private static final int FIELD_FOLDER_TYPE = 14;
|
||||
private static final int FIELD_IS_PLAYABLE = 15;
|
||||
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;
|
||||
|
||||
@Override
|
||||
|
|
@ -456,6 +502,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
bundle.putParcelable(keyForField(FIELD_MEDIA_URI), mediaUri);
|
||||
bundle.putByteArray(keyForField(FIELD_ARTWORK_DATA), artworkData);
|
||||
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) {
|
||||
bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle());
|
||||
|
|
@ -500,6 +549,9 @@ public final class MediaMetadata implements Bundleable {
|
|||
.setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI)))
|
||||
.setArtworkData(bundle.getByteArray(keyForField(FIELD_ARTWORK_DATA)))
|
||||
.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)));
|
||||
|
||||
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
|
||||
|
|
|
|||
|
|
@ -81,6 +81,18 @@ public final class TextInformationFrame extends Id3Frame {
|
|||
// Do nothing, invalid input.
|
||||
}
|
||||
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:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,9 @@ public class MediaMetadataTest {
|
|||
assertThat(mediaMetadata.folderType).isNull();
|
||||
assertThat(mediaMetadata.isPlayable).isNull();
|
||||
assertThat(mediaMetadata.year).isNull();
|
||||
assertThat(mediaMetadata.composer).isNull();
|
||||
assertThat(mediaMetadata.conductor).isNull();
|
||||
assertThat(mediaMetadata.writer).isNull();
|
||||
assertThat(mediaMetadata.extras).isNull();
|
||||
}
|
||||
|
||||
|
|
@ -101,6 +104,9 @@ public class MediaMetadataTest {
|
|||
.setFolderType(MediaMetadata.FOLDER_TYPE_PLAYLISTS)
|
||||
.setIsPlayable(true)
|
||||
.setYear(2000)
|
||||
.setComposer("Composer")
|
||||
.setConductor("Conductor")
|
||||
.setWriter("Writer")
|
||||
.setExtras(extras) // Extras is not implemented in MediaMetadata.equals(Object o).
|
||||
.build();
|
||||
|
||||
|
|
@ -117,6 +123,9 @@ public class MediaMetadataTest {
|
|||
String albumArtist = "album Artist";
|
||||
String trackNumberInfo = "11/17";
|
||||
String year = "2000";
|
||||
String composer = "composer";
|
||||
String conductor = "conductor";
|
||||
String writer = "writer";
|
||||
|
||||
List<Metadata.Entry> entries =
|
||||
ImmutableList.of(
|
||||
|
|
@ -128,20 +137,31 @@ public class MediaMetadataTest {
|
|||
/* id= */ "TP2", /* description= */ null, /* value= */ albumArtist),
|
||||
new TextInformationFrame(
|
||||
/* 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();
|
||||
|
||||
for (Metadata.Entry entry : entries) {
|
||||
entry.populateMediaMetadata(builder);
|
||||
}
|
||||
|
||||
assertThat(builder.build().title.toString()).isEqualTo(title);
|
||||
assertThat(builder.build().artist.toString()).isEqualTo(artist);
|
||||
assertThat(builder.build().albumTitle.toString()).isEqualTo(albumTitle);
|
||||
assertThat(builder.build().albumArtist.toString()).isEqualTo(albumArtist);
|
||||
assertThat(builder.build().trackNumber).isEqualTo(11);
|
||||
assertThat(builder.build().totalTrackCount).isEqualTo(17);
|
||||
assertThat(builder.build().year).isEqualTo(2000);
|
||||
MediaMetadata mediaMetadata = builder.build();
|
||||
|
||||
assertThat(mediaMetadata.title.toString()).isEqualTo(title);
|
||||
assertThat(mediaMetadata.artist.toString()).isEqualTo(artist);
|
||||
assertThat(mediaMetadata.albumTitle.toString()).isEqualTo(albumTitle);
|
||||
assertThat(mediaMetadata.albumArtist.toString()).isEqualTo(albumArtist);
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue