mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Rename MediaMetadata trackTitle and trackArtist to title and artist.
#minor-release PiperOrigin-RevId: 372537414
This commit is contained in:
parent
09a8993b56
commit
2914e574e6
@ -42,21 +42,19 @@ import java.util.List;
|
||||
samples.add(
|
||||
new MediaItem.Builder()
|
||||
.setUri("https://storage.googleapis.com/wvmedia/clear/h264/tears/tears.mpd")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder().setTrackTitle("Clear DASH: Tears").build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle("Clear DASH: Tears").build())
|
||||
.setMimeType(MIME_TYPE_DASH)
|
||||
.build());
|
||||
samples.add(
|
||||
new MediaItem.Builder()
|
||||
.setUri("https://storage.googleapis.com/shaka-demo-assets/angel-one-hls/hls.m3u8")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder().setTrackTitle("Clear HLS: Angel one").build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle("Clear HLS: Angel one").build())
|
||||
.setMimeType(MIME_TYPE_HLS)
|
||||
.build());
|
||||
samples.add(
|
||||
new MediaItem.Builder()
|
||||
.setUri("https://html5demos.com/assets/dizzy.mp4")
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTrackTitle("Clear MP4: Dizzy").build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle("Clear MP4: Dizzy").build())
|
||||
.setMimeType(MIME_TYPE_VIDEO_MP4)
|
||||
.build());
|
||||
|
||||
@ -65,7 +63,7 @@ import java.util.List;
|
||||
new MediaItem.Builder()
|
||||
.setUri(Uri.parse("https://storage.googleapis.com/wvmedia/cenc/h264/tears/tears.mpd"))
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder().setTrackTitle("Widevine DASH cenc: Tears").build())
|
||||
new MediaMetadata.Builder().setTitle("Widevine DASH cenc: Tears").build())
|
||||
.setMimeType(MIME_TYPE_DASH)
|
||||
.setDrmUuid(C.WIDEVINE_UUID)
|
||||
.setDrmLicenseUri("https://proxy.uat.widevine.com/proxy?provider=widevine_test")
|
||||
@ -74,7 +72,7 @@ import java.util.List;
|
||||
new MediaItem.Builder()
|
||||
.setUri("https://storage.googleapis.com/wvmedia/cbc1/h264/tears/tears_aes_cbc1.mpd")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder().setTrackTitle("Widevine DASH cbc1: Tears").build())
|
||||
new MediaMetadata.Builder().setTitle("Widevine DASH cbc1: Tears").build())
|
||||
.setMimeType(MIME_TYPE_DASH)
|
||||
.setDrmUuid(C.WIDEVINE_UUID)
|
||||
.setDrmLicenseUri("https://proxy.uat.widevine.com/proxy?provider=widevine_test")
|
||||
@ -83,7 +81,7 @@ import java.util.List;
|
||||
new MediaItem.Builder()
|
||||
.setUri("https://storage.googleapis.com/wvmedia/cbcs/h264/tears/tears_aes_cbcs.mpd")
|
||||
.setMediaMetadata(
|
||||
new MediaMetadata.Builder().setTrackTitle("Widevine DASH cbcs: Tears").build())
|
||||
new MediaMetadata.Builder().setTitle("Widevine DASH cbcs: Tears").build())
|
||||
.setMimeType(MIME_TYPE_DASH)
|
||||
.setDrmUuid(C.WIDEVINE_UUID)
|
||||
.setDrmLicenseUri("https://proxy.uat.widevine.com/proxy?provider=widevine_test")
|
||||
|
@ -213,7 +213,7 @@ public class MainActivity extends AppCompatActivity
|
||||
holder.item = Assertions.checkNotNull(playerManager.getItem(position));
|
||||
|
||||
TextView view = holder.textView;
|
||||
view.setText(holder.item.mediaMetadata.trackTitle);
|
||||
view.setText(holder.item.mediaMetadata.title);
|
||||
// TODO: Solve coloring using the theme's ColorStateList.
|
||||
view.setTextColor(
|
||||
ColorUtils.setAlphaComponent(
|
||||
@ -309,7 +309,7 @@ public class MainActivity extends AppCompatActivity
|
||||
@NonNull
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
View view = super.getView(position, convertView, parent);
|
||||
((TextView) view).setText(Util.castNonNull(getItem(position)).mediaMetadata.trackTitle);
|
||||
((TextView) view).setText(Util.castNonNull(getItem(position)).mediaMetadata.title);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +364,7 @@ public class DownloadTracker {
|
||||
private DownloadRequest buildDownloadRequest() {
|
||||
return downloadHelper
|
||||
.getDownloadRequest(
|
||||
Util.getUtf8Bytes(checkNotNull(mediaItem.mediaMetadata.trackTitle.toString())))
|
||||
Util.getUtf8Bytes(checkNotNull(mediaItem.mediaMetadata.title.toString())))
|
||||
.copyWithKeySetId(keySetId);
|
||||
}
|
||||
}
|
||||
|
@ -90,8 +90,8 @@ public class IntentUtil {
|
||||
MediaItem mediaItem = mediaItems.get(0);
|
||||
MediaItem.PlaybackProperties playbackProperties = checkNotNull(mediaItem.playbackProperties);
|
||||
intent.setAction(ACTION_VIEW).setData(mediaItem.playbackProperties.uri);
|
||||
if (mediaItem.mediaMetadata.trackTitle != null) {
|
||||
intent.putExtra(TITLE_EXTRA, mediaItem.mediaMetadata.trackTitle);
|
||||
if (mediaItem.mediaMetadata.title != null) {
|
||||
intent.putExtra(TITLE_EXTRA, mediaItem.mediaMetadata.title);
|
||||
}
|
||||
addPlaybackPropertiesToIntent(playbackProperties, intent, /* extrasKeySuffix= */ "");
|
||||
addClippingPropertiesToIntent(
|
||||
@ -106,8 +106,8 @@ public class IntentUtil {
|
||||
addPlaybackPropertiesToIntent(playbackProperties, intent, /* extrasKeySuffix= */ "_" + i);
|
||||
addClippingPropertiesToIntent(
|
||||
mediaItem.clippingProperties, intent, /* extrasKeySuffix= */ "_" + i);
|
||||
if (mediaItem.mediaMetadata.trackTitle != null) {
|
||||
intent.putExtra(TITLE_EXTRA + ("_" + i), mediaItem.mediaMetadata.trackTitle);
|
||||
if (mediaItem.mediaMetadata.title != null) {
|
||||
intent.putExtra(TITLE_EXTRA + ("_" + i), mediaItem.mediaMetadata.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,7 +121,7 @@ public class IntentUtil {
|
||||
new MediaItem.Builder()
|
||||
.setUri(uri)
|
||||
.setMimeType(mimeType)
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTrackTitle(title).build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build())
|
||||
.setAdTagUri(intent.getStringExtra(AD_TAG_URI_EXTRA + extrasKeySuffix))
|
||||
.setSubtitles(createSubtitlesFromIntent(intent, extrasKeySuffix))
|
||||
.setClipStartPositionMs(
|
||||
|
@ -433,7 +433,7 @@ public class SampleChooserActivity extends AppCompatActivity
|
||||
Util.getAdaptiveMimeTypeForContentType(Util.inferContentType(uri, extension));
|
||||
mediaItem
|
||||
.setUri(uri)
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTrackTitle(title).build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle(title).build())
|
||||
.setMimeType(adaptiveMimeType);
|
||||
if (subtitleUri != null) {
|
||||
MediaItem.Subtitle subtitle =
|
||||
|
@ -7,14 +7,14 @@ title: Retrieving metadata
|
||||
The metadata of the media can be retrieved during playback in multiple ways. The
|
||||
most straightforward is to listen for the
|
||||
`Player.EventListener#onMediaMetadataChanged` event; this will provide a
|
||||
[`MediaMetadata`][] object for use, which has fields such as `trackTitle` and
|
||||
[`MediaMetadata`][] object for use, which has fields such as `title` and
|
||||
`albumArtist`. Alternatively, calling `Player#getMediaMetadata` returns the same
|
||||
object.
|
||||
|
||||
~~~
|
||||
public void onMediaMetadataChanged(MediaMetadata mediaMetadata) {
|
||||
if (mediaMetadata.trackTitle != null) {
|
||||
handleTrackTitle(mediaMetadata.trackTitle);
|
||||
if (mediaMetadata.title != null) {
|
||||
handleTitle(mediaMetadata.title);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ public final class DefaultMediaItemConverter implements MediaItemConverter {
|
||||
}
|
||||
MediaMetadata metadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
|
||||
if (item.mediaMetadata.title != null) {
|
||||
metadata.putString(MediaMetadata.KEY_TITLE, item.mediaMetadata.title);
|
||||
metadata.putString(MediaMetadata.KEY_TITLE, item.mediaMetadata.title.toString());
|
||||
}
|
||||
MediaInfo mediaInfo =
|
||||
new MediaInfo.Builder(item.playbackProperties.uri.toString())
|
||||
|
@ -123,14 +123,14 @@ public class DefaultMediaItemConverter implements MediaItemConverter {
|
||||
* MediaItem ExoPlayer MediaItem}.
|
||||
*/
|
||||
protected androidx.media2.common.MediaMetadata getMetadata(MediaItem exoPlayerMediaItem) {
|
||||
@Nullable String title = exoPlayerMediaItem.mediaMetadata.title;
|
||||
@Nullable CharSequence title = exoPlayerMediaItem.mediaMetadata.title;
|
||||
|
||||
androidx.media2.common.MediaMetadata.Builder metadataBuilder =
|
||||
new androidx.media2.common.MediaMetadata.Builder()
|
||||
.putString(METADATA_KEY_MEDIA_ID, exoPlayerMediaItem.mediaId);
|
||||
if (title != null) {
|
||||
metadataBuilder.putString(METADATA_KEY_TITLE, title);
|
||||
metadataBuilder.putString(METADATA_KEY_DISPLAY_TITLE, title);
|
||||
metadataBuilder.putString(METADATA_KEY_TITLE, title.toString());
|
||||
metadataBuilder.putString(METADATA_KEY_DISPLAY_TITLE, title.toString());
|
||||
}
|
||||
return metadataBuilder.build();
|
||||
}
|
||||
|
@ -36,8 +36,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
/** A builder for {@link MediaMetadata} instances. */
|
||||
public static final class Builder {
|
||||
|
||||
@Nullable private CharSequence trackTitle;
|
||||
@Nullable private CharSequence trackArtist;
|
||||
@Nullable private CharSequence title;
|
||||
@Nullable private CharSequence artist;
|
||||
@Nullable private CharSequence albumTitle;
|
||||
@Nullable private CharSequence albumArtist;
|
||||
@Nullable private CharSequence displayTitle;
|
||||
@ -50,32 +50,26 @@ public final class MediaMetadata implements Bundleable {
|
||||
public Builder() {}
|
||||
|
||||
private Builder(MediaMetadata mediaMetadata) {
|
||||
this.trackTitle = mediaMetadata.trackTitle;
|
||||
this.trackArtist = mediaMetadata.trackArtist;
|
||||
this.title = mediaMetadata.title;
|
||||
this.artist = mediaMetadata.artist;
|
||||
this.albumTitle = mediaMetadata.albumTitle;
|
||||
this.albumArtist = mediaMetadata.albumArtist;
|
||||
this.displayTitle = mediaMetadata.displayTitle;
|
||||
this.subtitle = mediaMetadata.subtitle;
|
||||
this.description = mediaMetadata.description;
|
||||
this.mediaUri = mediaMetadata.mediaUri;
|
||||
this.userRating = mediaMetadata.userRating;
|
||||
this.overallRating = mediaMetadata.overallRating;
|
||||
}
|
||||
|
||||
/** @deprecated Use {@link #setTrackTitle(CharSequence)} instead. */
|
||||
@Deprecated
|
||||
public Builder setTitle(@Nullable String title) {
|
||||
this.trackTitle = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the optional track title. */
|
||||
public Builder setTrackTitle(@Nullable CharSequence trackTitle) {
|
||||
this.trackTitle = trackTitle;
|
||||
public Builder setTitle(@Nullable CharSequence title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTrackArtist(@Nullable CharSequence trackArtist) {
|
||||
this.trackArtist = trackArtist;
|
||||
public Builder setArtist(@Nullable CharSequence artist) {
|
||||
this.artist = artist;
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -166,11 +160,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
/** Empty {@link MediaMetadata}. */
|
||||
public static final MediaMetadata EMPTY = new MediaMetadata.Builder().build();
|
||||
|
||||
/** @deprecated Use {@link #trackTitle} instead. */
|
||||
@Deprecated @Nullable public final String title;
|
||||
|
||||
@Nullable public final CharSequence trackTitle;
|
||||
@Nullable public final CharSequence trackArtist;
|
||||
@Nullable public final CharSequence title;
|
||||
@Nullable public final CharSequence artist;
|
||||
@Nullable public final CharSequence albumTitle;
|
||||
@Nullable public final CharSequence albumArtist;
|
||||
@Nullable public final CharSequence displayTitle;
|
||||
@ -181,9 +172,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Nullable public final Rating overallRating;
|
||||
|
||||
private MediaMetadata(Builder builder) {
|
||||
this.title = builder.trackTitle != null ? builder.trackTitle.toString() : null;
|
||||
this.trackTitle = builder.trackTitle;
|
||||
this.trackArtist = builder.trackArtist;
|
||||
this.title = builder.title;
|
||||
this.artist = builder.artist;
|
||||
this.albumTitle = builder.albumTitle;
|
||||
this.albumArtist = builder.albumArtist;
|
||||
this.displayTitle = builder.displayTitle;
|
||||
@ -208,8 +198,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
return false;
|
||||
}
|
||||
MediaMetadata that = (MediaMetadata) obj;
|
||||
return Util.areEqual(trackTitle, that.trackTitle)
|
||||
&& Util.areEqual(trackArtist, that.trackArtist)
|
||||
return Util.areEqual(title, that.title)
|
||||
&& Util.areEqual(artist, that.artist)
|
||||
&& Util.areEqual(albumTitle, that.albumTitle)
|
||||
&& Util.areEqual(albumArtist, that.albumArtist)
|
||||
&& Util.areEqual(displayTitle, that.displayTitle)
|
||||
@ -223,8 +213,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(
|
||||
trackTitle,
|
||||
trackArtist,
|
||||
title,
|
||||
artist,
|
||||
albumTitle,
|
||||
albumArtist,
|
||||
displayTitle,
|
||||
@ -240,8 +230,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef({
|
||||
FIELD_TRACK_TITLE,
|
||||
FIELD_TRACK_ARTIST,
|
||||
FIELD_TITLE,
|
||||
FIELD_ARTIST,
|
||||
FIELD_ALBUM_TITLE,
|
||||
FIELD_ALBUM_ARTIST,
|
||||
FIELD_DISPLAY_TITLE,
|
||||
@ -253,8 +243,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
})
|
||||
private @interface FieldNumber {}
|
||||
|
||||
private static final int FIELD_TRACK_TITLE = 0;
|
||||
private static final int FIELD_TRACK_ARTIST = 1;
|
||||
private static final int FIELD_TITLE = 0;
|
||||
private static final int FIELD_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;
|
||||
@ -267,8 +257,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
@Override
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putCharSequence(keyForField(FIELD_TRACK_TITLE), trackTitle);
|
||||
bundle.putCharSequence(keyForField(FIELD_TRACK_ARTIST), trackArtist);
|
||||
bundle.putCharSequence(keyForField(FIELD_TITLE), title);
|
||||
bundle.putCharSequence(keyForField(FIELD_ARTIST), artist);
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_TITLE), albumTitle);
|
||||
bundle.putCharSequence(keyForField(FIELD_ALBUM_ARTIST), albumArtist);
|
||||
bundle.putCharSequence(keyForField(FIELD_DISPLAY_TITLE), displayTitle);
|
||||
@ -292,8 +282,8 @@ public final class MediaMetadata implements Bundleable {
|
||||
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)))
|
||||
.setTitle(bundle.getCharSequence(keyForField(FIELD_TITLE)))
|
||||
.setArtist(bundle.getCharSequence(keyForField(FIELD_ARTIST)))
|
||||
.setAlbumTitle(bundle.getCharSequence(keyForField(FIELD_ALBUM_TITLE)))
|
||||
.setAlbumArtist(bundle.getCharSequence(keyForField(FIELD_ALBUM_ARTIST)))
|
||||
.setDisplayTitle(bundle.getCharSequence(keyForField(FIELD_DISPLAY_TITLE)))
|
||||
|
@ -46,11 +46,11 @@ public final class TextInformationFrame extends Id3Frame {
|
||||
switch (id) {
|
||||
case "TT2":
|
||||
case "TIT2":
|
||||
builder.setTrackTitle(value);
|
||||
builder.setTitle(value);
|
||||
break;
|
||||
case "TP1":
|
||||
case "TPE1":
|
||||
builder.setTrackArtist(value);
|
||||
builder.setArtist(value);
|
||||
break;
|
||||
case "TP2":
|
||||
case "TPE2":
|
||||
|
@ -299,7 +299,7 @@ public class MediaItemTest {
|
||||
|
||||
@Test
|
||||
public void builderSetMediaMetadata_setsMetadata() {
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTrackTitle("title").build();
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("title").build();
|
||||
|
||||
MediaItem mediaItem =
|
||||
new MediaItem.Builder().setUri(URI_STRING).setMediaMetadata(mediaMetadata).build();
|
||||
@ -368,7 +368,7 @@ public class MediaItemTest {
|
||||
.setDrmSessionForClearTypes(Collections.singletonList(C.TRACK_TYPE_AUDIO))
|
||||
.setDrmKeySetId(new byte[] {1, 2, 3})
|
||||
.setMediaId("mediaId")
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTrackTitle("title").build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle("title").build())
|
||||
.setMimeType(MimeTypes.APPLICATION_MP4)
|
||||
.setUri(URI_STRING)
|
||||
.setStreamKeys(Collections.singletonList(new StreamKey(1, 0, 0)))
|
||||
@ -404,7 +404,7 @@ public class MediaItemTest {
|
||||
.setLiveMaxOffsetMs(4_444)
|
||||
.setLiveMinPlaybackSpeed(.9f)
|
||||
.setLiveMaxPlaybackSpeed(1.1f)
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTrackTitle("title").build())
|
||||
.setMediaMetadata(new MediaMetadata.Builder().setTitle("title").build())
|
||||
.setClipStartPositionMs(100)
|
||||
.setClipEndPositionMs(1_000)
|
||||
.setClipRelativeToDefaultPosition(true)
|
||||
|
@ -31,21 +31,21 @@ public class MediaMetadataTest {
|
||||
public void builder_minimal_correctDefaults() {
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().build();
|
||||
|
||||
assertThat(mediaMetadata.trackTitle).isNull();
|
||||
assertThat(mediaMetadata.title).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderSetsTrackTitle_setsTrackTitle() {
|
||||
public void builderSetTitle_setsTitle() {
|
||||
String title = "title";
|
||||
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTrackTitle(title).build();
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle(title).build();
|
||||
|
||||
assertThat(mediaMetadata.trackTitle.toString()).isEqualTo(title);
|
||||
assertThat(mediaMetadata.title.toString()).isEqualTo(title);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void roundTripViaBundle_yieldsEqualInstance() {
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTrackTitle("title").build();
|
||||
MediaMetadata mediaMetadata = new MediaMetadata.Builder().setTitle("title").build();
|
||||
|
||||
assertThat(MediaMetadata.CREATOR.fromBundle(mediaMetadata.toBundle())).isEqualTo(mediaMetadata);
|
||||
}
|
||||
@ -58,6 +58,6 @@ public class MediaMetadataTest {
|
||||
MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
|
||||
|
||||
entry.populateMediaMetadata(builder);
|
||||
assertThat(builder.build().trackTitle.toString()).isEqualTo(title);
|
||||
assertThat(builder.build().title.toString()).isEqualTo(title);
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ public final class IcyInfo implements Metadata.Entry {
|
||||
@Override
|
||||
public void populateMediaMetadata(MediaMetadata.Builder builder) {
|
||||
if (title != null) {
|
||||
builder.setTrackTitle(title);
|
||||
builder.setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user