Commit 9ec6992c by samrobinson Committed by Oliver Woodman

Populate MediaMetadata title from IcyInfo and TextInformationFrame.

PiperOrigin-RevId: 366272937
parent a5c47243
...@@ -19,6 +19,7 @@ import android.os.Parcel; ...@@ -19,6 +19,7 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -48,6 +49,13 @@ public final class Metadata implements Parcelable { ...@@ -48,6 +49,13 @@ public final class Metadata implements Parcelable {
default byte[] getWrappedMetadataBytes() { default byte[] getWrappedMetadataBytes() {
return null; 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; private final Entry[] entries;
......
...@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull; ...@@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
/** /**
...@@ -43,6 +44,18 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -43,6 +44,18 @@ public final class TextInformationFrame extends Id3Frame {
} }
@Override @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) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
......
...@@ -18,6 +18,8 @@ package com.google.android.exoplayer2; ...@@ -18,6 +18,8 @@ package com.google.android.exoplayer2;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import androidx.test.ext.junit.runners.AndroidJUnit4; 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.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -47,4 +49,15 @@ public class MediaMetadataTest { ...@@ -47,4 +49,15 @@ public class MediaMetadataTest {
assertThat(MediaMetadata.CREATOR.fromBundle(mediaMetadata.toBundle())).isEqualTo(mediaMetadata); 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; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.metadata.icy;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.metadata.Metadata; import com.google.android.exoplayer2.metadata.Metadata;
import com.google.android.exoplayer2.util.Assertions; import com.google.android.exoplayer2.util.Assertions;
import java.util.Arrays; import java.util.Arrays;
...@@ -53,6 +54,13 @@ public final class IcyInfo implements Metadata.Entry { ...@@ -53,6 +54,13 @@ public final class IcyInfo implements Metadata.Entry {
} }
@Override @Override
public void populateMediaMetadata(MediaMetadata.Builder builder) {
if (title != null) {
builder.setTitle(title);
}
}
@Override
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
......
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