Populate MediaMetadata title from IcyInfo and TextInformationFrame.
PiperOrigin-RevId: 366272937
This commit is contained in:
parent
a5c47243f4
commit
9ec6992ca1
@ -19,6 +19,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.MediaMetadata;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@ -48,6 +49,13 @@ public final class Metadata implements Parcelable {
|
||||
default byte[] getWrappedMetadataBytes() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the {@link MediaMetadata.Builder} with the type specific values stored in this Entry.
|
||||
*
|
||||
* @param builder The builder to be updated.
|
||||
*/
|
||||
default void populateMediaMetadata(MediaMetadata.Builder builder) {}
|
||||
}
|
||||
|
||||
private final Entry[] entries;
|
||||
|
@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.MediaMetadata;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
|
||||
/**
|
||||
@ -42,6 +43,18 @@ public final class TextInformationFrame extends Id3Frame {
|
||||
value = castNonNull(in.readString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateMediaMetadata(MediaMetadata.Builder builder) {
|
||||
switch (id) {
|
||||
case "TT2":
|
||||
case "TIT2":
|
||||
builder.setTitle(value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -18,6 +18,8 @@ package com.google.android.exoplayer2;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.metadata.id3.TextInformationFrame;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -47,4 +49,15 @@ public class MediaMetadataTest {
|
||||
|
||||
assertThat(MediaMetadata.CREATOR.fromBundle(mediaMetadata.toBundle())).isEqualTo(mediaMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void builderPopulatedFromMetadataEntry_setsTitleCorrectly() {
|
||||
String title = "the title";
|
||||
Metadata.Entry entry =
|
||||
new TextInformationFrame(/* id= */ "TT2", /* description= */ null, /* value= */ title);
|
||||
MediaMetadata.Builder builder = MediaMetadata.EMPTY.buildUpon();
|
||||
|
||||
entry.populateMediaMetadata(builder);
|
||||
assertThat(builder.build().title).isEqualTo(title);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.metadata.icy;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.exoplayer2.MediaMetadata;
|
||||
import com.google.android.exoplayer2.metadata.Metadata;
|
||||
import com.google.android.exoplayer2.util.Assertions;
|
||||
import java.util.Arrays;
|
||||
@ -52,6 +53,13 @@ public final class IcyInfo implements Metadata.Entry {
|
||||
url = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateMediaMetadata(MediaMetadata.Builder builder) {
|
||||
if (title != null) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user