Commit 79316aa5 by samrobinson Committed by bachinger

Add track artist, album artist and album title to MediaMetadata.

#minor-release

PiperOrigin-RevId: 370881618
parent 64e32d7c
...@@ -20,23 +20,33 @@ import androidx.annotation.IntDef; ...@@ -20,23 +20,33 @@ import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import com.google.common.base.Objects;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.List; import java.util.List;
/** Metadata of a {@link MediaItem} or a playlist. */ /**
* Metadata of a {@link MediaItem}, playlist, or a combination of multiple sources of {@link
* Metadata}.
*/
public final class MediaMetadata implements Bundleable { public final class MediaMetadata implements Bundleable {
/** A builder for {@link MediaMetadata} instances. */ /** A builder for {@link MediaMetadata} instances. */
public static final class Builder { public static final class Builder {
@Nullable private CharSequence trackTitle; @Nullable private CharSequence trackTitle;
@Nullable private CharSequence trackArtist;
@Nullable private CharSequence albumTitle;
@Nullable private CharSequence albumArtist;
public Builder() {} public Builder() {}
private Builder(MediaMetadata mediaMetadata) { private Builder(MediaMetadata mediaMetadata) {
this.trackTitle = mediaMetadata.trackTitle; this.trackTitle = mediaMetadata.trackTitle;
this.trackArtist = mediaMetadata.trackArtist;
this.albumTitle = mediaMetadata.albumTitle;
this.albumArtist = mediaMetadata.albumArtist;
} }
/** @deprecated Use {@link #setTrackTitle(CharSequence)} instead. */ /** @deprecated Use {@link #setTrackTitle(CharSequence)} instead. */
...@@ -52,6 +62,21 @@ public final class MediaMetadata implements Bundleable { ...@@ -52,6 +62,21 @@ public final class MediaMetadata implements Bundleable {
return this; return this;
} }
public Builder setTrackArtist(@Nullable CharSequence trackArtist) {
this.trackArtist = trackArtist;
return this;
}
public Builder setAlbumTitle(@Nullable CharSequence albumTitle) {
this.albumTitle = albumTitle;
return this;
}
public Builder setAlbumArtist(@Nullable CharSequence albumArtist) {
this.albumArtist = albumArtist;
return this;
}
/** /**
* Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}. * Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}.
* *
...@@ -102,12 +127,17 @@ public final class MediaMetadata implements Bundleable { ...@@ -102,12 +127,17 @@ public final class MediaMetadata implements Bundleable {
/** @deprecated Use {@link #trackTitle} instead. */ /** @deprecated Use {@link #trackTitle} instead. */
@Deprecated @Nullable public final String title; @Deprecated @Nullable public final String title;
/** Optional track title. */
@Nullable public final CharSequence trackTitle; @Nullable public final CharSequence trackTitle;
@Nullable public final CharSequence trackArtist;
@Nullable public final CharSequence albumTitle;
@Nullable public final CharSequence albumArtist;
private MediaMetadata(Builder builder) { private MediaMetadata(Builder builder) {
this.title = builder.trackTitle != null ? builder.trackTitle.toString() : null; this.title = builder.trackTitle != null ? builder.trackTitle.toString() : null;
this.trackTitle = builder.trackTitle; this.trackTitle = builder.trackTitle;
this.trackArtist = builder.trackArtist;
this.albumTitle = builder.albumTitle;
this.albumArtist = builder.albumArtist;
} }
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */ /** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
...@@ -123,29 +153,37 @@ public final class MediaMetadata implements Bundleable { ...@@ -123,29 +153,37 @@ public final class MediaMetadata implements Bundleable {
if (obj == null || getClass() != obj.getClass()) { if (obj == null || getClass() != obj.getClass()) {
return false; return false;
} }
MediaMetadata other = (MediaMetadata) obj; MediaMetadata that = (MediaMetadata) obj;
return Util.areEqual(trackTitle, that.trackTitle)
return Util.areEqual(trackTitle, other.trackTitle); && Util.areEqual(trackArtist, that.trackArtist)
&& Util.areEqual(albumTitle, that.albumTitle)
&& Util.areEqual(albumArtist, that.albumArtist);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return trackTitle == null ? 0 : trackTitle.hashCode(); return Objects.hashCode(trackTitle, trackArtist, albumTitle, albumArtist);
} }
// Bundleable implementation. // Bundleable implementation.
@Documented @Documented
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
@IntDef({FIELD_TRACK_TITLE}) @IntDef({FIELD_TRACK_TITLE, FIELD_TRACK_ARTIST, FIELD_ALBUM_TITLE, FIELD_ALBUM_ARTIST})
private @interface FieldNumber {} private @interface FieldNumber {}
private static final int FIELD_TRACK_TITLE = 0; private static final int FIELD_TRACK_TITLE = 0;
private static final int FIELD_TRACK_ARTIST = 1;
private static final int FIELD_ALBUM_TITLE = 2;
private static final int FIELD_ALBUM_ARTIST = 3;
@Override @Override
public Bundle toBundle() { public Bundle toBundle() {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putCharSequence(keyForField(FIELD_TRACK_TITLE), trackTitle); bundle.putCharSequence(keyForField(FIELD_TRACK_TITLE), trackTitle);
bundle.putCharSequence(keyForField(FIELD_TRACK_ARTIST), trackArtist);
bundle.putCharSequence(keyForField(FIELD_ALBUM_TITLE), albumTitle);
bundle.putCharSequence(keyForField(FIELD_ALBUM_ARTIST), albumArtist);
return bundle; return bundle;
} }
...@@ -154,6 +192,9 @@ public final class MediaMetadata implements Bundleable { ...@@ -154,6 +192,9 @@ public final class MediaMetadata implements Bundleable {
bundle -> bundle ->
new MediaMetadata.Builder() new MediaMetadata.Builder()
.setTrackTitle(bundle.getCharSequence(keyForField(FIELD_TRACK_TITLE))) .setTrackTitle(bundle.getCharSequence(keyForField(FIELD_TRACK_TITLE)))
.setTrackArtist(bundle.getCharSequence(keyForField(FIELD_TRACK_ARTIST)))
.setAlbumTitle(bundle.getCharSequence(keyForField(FIELD_ALBUM_TITLE)))
.setAlbumArtist(bundle.getCharSequence(keyForField(FIELD_ALBUM_ARTIST)))
.build(); .build();
private static String keyForField(@FieldNumber int field) { private static String keyForField(@FieldNumber int field) {
......
...@@ -48,6 +48,18 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -48,6 +48,18 @@ public final class TextInformationFrame extends Id3Frame {
case "TIT2": case "TIT2":
builder.setTrackTitle(value); builder.setTrackTitle(value);
break; break;
case "TP1":
case "TPE1":
builder.setTrackArtist(value);
break;
case "TP2":
case "TPE2":
builder.setAlbumArtist(value);
break;
case "TAL":
case "TALB":
builder.setAlbumTitle(value);
break;
default: default:
break; break;
} }
...@@ -62,7 +74,8 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -62,7 +74,8 @@ public final class TextInformationFrame extends Id3Frame {
return false; return false;
} }
TextInformationFrame other = (TextInformationFrame) obj; TextInformationFrame other = (TextInformationFrame) obj;
return id.equals(other.id) && Util.areEqual(description, other.description) return Util.areEqual(id, other.id)
&& Util.areEqual(description, other.description)
&& Util.areEqual(value, other.value); && Util.areEqual(value, other.value);
} }
...@@ -101,7 +114,5 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -101,7 +114,5 @@ public final class TextInformationFrame extends Id3Frame {
public TextInformationFrame[] newArray(int size) { public TextInformationFrame[] newArray(int size) {
return new TextInformationFrame[size]; return new TextInformationFrame[size];
} }
}; };
} }
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