Add fields to MediaMetadata requested by MediaAPIs
#minor-release PiperOrigin-RevId: 372448985
This commit is contained in:
parent
15ce148877
commit
09a8993b56
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.IntDef;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -39,6 +40,12 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Nullable private CharSequence trackArtist;
|
||||
@Nullable private CharSequence albumTitle;
|
||||
@Nullable private CharSequence albumArtist;
|
||||
@Nullable private CharSequence displayTitle;
|
||||
@Nullable private CharSequence subtitle;
|
||||
@Nullable private CharSequence description;
|
||||
@Nullable private Uri mediaUri;
|
||||
@Nullable private Rating userRating;
|
||||
@Nullable private Rating overallRating;
|
||||
|
||||
public Builder() {}
|
||||
|
||||
@ -47,6 +54,11 @@ public final class MediaMetadata implements Bundleable {
|
||||
this.trackArtist = mediaMetadata.trackArtist;
|
||||
this.albumTitle = mediaMetadata.albumTitle;
|
||||
this.albumArtist = mediaMetadata.albumArtist;
|
||||
this.displayTitle = mediaMetadata.displayTitle;
|
||||
this.subtitle = mediaMetadata.subtitle;
|
||||
this.mediaUri = mediaMetadata.mediaUri;
|
||||
this.userRating = mediaMetadata.userRating;
|
||||
this.overallRating = mediaMetadata.overallRating;
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link #setTrackTitle(CharSequence)} instead. */
|
||||
@ -77,6 +89,36 @@ public final class MediaMetadata implements Bundleable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDisplayTitle(@Nullable CharSequence displayTitle) {
|
||||
this.displayTitle = displayTitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSubtitle(@Nullable CharSequence subtitle) {
|
||||
this.subtitle = subtitle;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescription(@Nullable CharSequence description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMediaUri(@Nullable Uri mediaUri) {
|
||||
this.mediaUri = mediaUri;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setUserRating(@Nullable Rating userRating) {
|
||||
this.userRating = userRating;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setOverallRating(@Nullable Rating overallRating) {
|
||||
this.overallRating = overallRating;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets all fields supported by the {@link Metadata.Entry entries} within the {@link Metadata}.
|
||||
*
|
||||
@ -131,6 +173,12 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Nullable public final CharSequence trackArtist;
|
||||
@Nullable public final CharSequence albumTitle;
|
||||
@Nullable public final CharSequence albumArtist;
|
||||
@Nullable public final CharSequence displayTitle;
|
||||
@Nullable public final CharSequence subtitle;
|
||||
@Nullable public final CharSequence description;
|
||||
@Nullable public final Uri mediaUri;
|
||||
@Nullable public final Rating userRating;
|
||||
@Nullable public final Rating overallRating;
|
||||
|
||||
private MediaMetadata(Builder builder) {
|
||||
this.title = builder.trackTitle != null ? builder.trackTitle.toString() : null;
|
||||
@ -138,6 +186,12 @@ public final class MediaMetadata implements Bundleable {
|
||||
this.trackArtist = builder.trackArtist;
|
||||
this.albumTitle = builder.albumTitle;
|
||||
this.albumArtist = builder.albumArtist;
|
||||
this.displayTitle = builder.displayTitle;
|
||||
this.subtitle = builder.subtitle;
|
||||
this.description = builder.description;
|
||||
this.mediaUri = builder.mediaUri;
|
||||
this.userRating = builder.userRating;
|
||||
this.overallRating = builder.overallRating;
|
||||
}
|
||||
|
||||
/** Returns a new {@link Builder} instance with the current {@link MediaMetadata} fields. */
|
||||
@ -157,25 +211,58 @@ public final class MediaMetadata implements Bundleable {
|
||||
return Util.areEqual(trackTitle, that.trackTitle)
|
||||
&& Util.areEqual(trackArtist, that.trackArtist)
|
||||
&& Util.areEqual(albumTitle, that.albumTitle)
|
||||
&& Util.areEqual(albumArtist, that.albumArtist);
|
||||
&& Util.areEqual(albumArtist, that.albumArtist)
|
||||
&& Util.areEqual(displayTitle, that.displayTitle)
|
||||
&& Util.areEqual(subtitle, that.subtitle)
|
||||
&& Util.areEqual(description, that.description)
|
||||
&& Util.areEqual(mediaUri, that.mediaUri)
|
||||
&& Util.areEqual(userRating, that.userRating)
|
||||
&& Util.areEqual(overallRating, that.overallRating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(trackTitle, trackArtist, albumTitle, albumArtist);
|
||||
return Objects.hashCode(
|
||||
trackTitle,
|
||||
trackArtist,
|
||||
albumTitle,
|
||||
albumArtist,
|
||||
displayTitle,
|
||||
subtitle,
|
||||
description,
|
||||
mediaUri,
|
||||
userRating,
|
||||
overallRating);
|
||||
}
|
||||
|
||||
// Bundleable implementation.
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({FIELD_TRACK_TITLE, FIELD_TRACK_ARTIST, FIELD_ALBUM_TITLE, FIELD_ALBUM_ARTIST})
|
||||
@IntDef({
|
||||
FIELD_TRACK_TITLE,
|
||||
FIELD_TRACK_ARTIST,
|
||||
FIELD_ALBUM_TITLE,
|
||||
FIELD_ALBUM_ARTIST,
|
||||
FIELD_DISPLAY_TITLE,
|
||||
FIELD_SUBTITLE,
|
||||
FIELD_DESCRIPTION,
|
||||
FIELD_MEDIA_URI,
|
||||
FIELD_USER_RATING,
|
||||
FIELD_OVERALL_RATING,
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
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;
|
||||
private static final int FIELD_DISPLAY_TITLE = 4;
|
||||
private static final int FIELD_SUBTITLE = 5;
|
||||
private static final int FIELD_DESCRIPTION = 6;
|
||||
private static final int FIELD_MEDIA_URI = 7;
|
||||
private static final int FIELD_USER_RATING = 8;
|
||||
private static final int FIELD_OVERALL_RATING = 9;
|
||||
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
@ -184,18 +271,51 @@ public final class MediaMetadata implements Bundleable {
|
||||
bundle.putCharSequence(keyForField(FIELD_TRACK_ARTIST), trackArtist);
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_TITLE), albumTitle);
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_ARTIST), albumArtist);
|
||||
bundle.putCharSequence(keyForField(FIELD_DISPLAY_TITLE), displayTitle);
|
||||
bundle.putCharSequence(keyForField(FIELD_SUBTITLE), subtitle);
|
||||
bundle.putCharSequence(keyForField(FIELD_DESCRIPTION), description);
|
||||
bundle.putParcelable(keyForField(FIELD_MEDIA_URI), mediaUri);
|
||||
|
||||
if (userRating != null) {
|
||||
bundle.putBundle(keyForField(FIELD_USER_RATING), userRating.toBundle());
|
||||
}
|
||||
if (overallRating != null) {
|
||||
bundle.putBundle(keyForField(FIELD_OVERALL_RATING), overallRating.toBundle());
|
||||
}
|
||||
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/** Object that can restore {@link MediaMetadata} from a {@link Bundle}. */
|
||||
public static final Creator<MediaMetadata> CREATOR =
|
||||
bundle ->
|
||||
new MediaMetadata.Builder()
|
||||
public static final Creator<MediaMetadata> CREATOR = MediaMetadata::fromBundle;
|
||||
|
||||
private static MediaMetadata fromBundle(Bundle bundle) {
|
||||
Builder builder = new Builder();
|
||||
builder
|
||||
.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();
|
||||
.setDisplayTitle(bundle.getCharSequence(keyForField(FIELD_DISPLAY_TITLE)))
|
||||
.setSubtitle(bundle.getCharSequence(keyForField(FIELD_SUBTITLE)))
|
||||
.setDescription(bundle.getCharSequence(keyForField(FIELD_DESCRIPTION)))
|
||||
.setMediaUri(bundle.getParcelable(keyForField(FIELD_MEDIA_URI)));
|
||||
|
||||
if (bundle.containsKey(keyForField(FIELD_USER_RATING))) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(keyForField(FIELD_USER_RATING));
|
||||
if (fieldBundle != null) {
|
||||
builder.setUserRating(Rating.CREATOR.fromBundle(fieldBundle));
|
||||
}
|
||||
}
|
||||
if (bundle.containsKey(keyForField(FIELD_OVERALL_RATING))) {
|
||||
@Nullable Bundle fieldBundle = bundle.getBundle(keyForField(FIELD_OVERALL_RATING));
|
||||
if (fieldBundle != null) {
|
||||
builder.setUserRating(Rating.CREATOR.fromBundle(fieldBundle));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String keyForField(@FieldNumber int field) {
|
||||
return Integer.toString(field, Character.MAX_RADIX);
|
||||
|
Loading…
x
Reference in New Issue
Block a user