Fix second-order issues

Fix second-order issues stemming from the addition of multi-value tags.
parent b054813e
...@@ -824,7 +824,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou ...@@ -824,7 +824,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
if (entry instanceof TextInformationFrame) { if (entry instanceof TextInformationFrame) {
TextInformationFrame textFrame = (TextInformationFrame) entry; TextInformationFrame textFrame = (TextInformationFrame) entry;
if ("TXXX".equals(textFrame.id)) { if ("TXXX".equals(textFrame.id)) {
streamPlayer.triggerUserTextReceived(textFrame.value); streamPlayer.triggerUserTextReceived(textFrame.values[0]);
} }
} else if (entry instanceof EventMessage) { } else if (entry instanceof EventMessage) {
EventMessage eventMessage = (EventMessage) entry; EventMessage eventMessage = (EventMessage) entry;
......
...@@ -107,7 +107,7 @@ public class MetadataRendererTest { ...@@ -107,7 +107,7 @@ public class MetadataRendererTest {
assertThat(metadata).hasSize(1); assertThat(metadata).hasSize(1);
assertThat(metadata.get(0).length()).isEqualTo(1); assertThat(metadata.get(0).length()).isEqualTo(1);
TextInformationFrame expectedId3Frame = TextInformationFrame expectedId3Frame =
new TextInformationFrame("TXXX", "Test description", "Test value"); new TextInformationFrame("TXXX", "Test description", new String[] { "Test value" });
assertThat(metadata.get(0).get(0)).isEqualTo(expectedId3Frame); assertThat(metadata.get(0).get(0)).isEqualTo(expectedId3Frame);
} }
......
...@@ -592,7 +592,7 @@ public final class Mp3Extractor implements Extractor { ...@@ -592,7 +592,7 @@ public final class Mp3Extractor implements Extractor {
Metadata.Entry entry = metadata.get(i); Metadata.Entry entry = metadata.get(i);
if (entry instanceof TextInformationFrame if (entry instanceof TextInformationFrame
&& ((TextInformationFrame) entry).id.equals("TLEN")) { && ((TextInformationFrame) entry).id.equals("TLEN")) {
return Util.msToUs(Long.parseLong(((TextInformationFrame) entry).value)); return Util.msToUs(Long.parseLong(((TextInformationFrame) entry).values[0]));
} }
} }
} }
......
...@@ -464,6 +464,10 @@ public final class Id3Decoder extends SimpleMetadataDecoder { ...@@ -464,6 +464,10 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
int valueStartIndex = descriptionEndIndex + delimiterLength(encoding); int valueStartIndex = descriptionEndIndex + delimiterLength(encoding);
if (valueStartIndex >= data.length) {
return new TextInformationFrame("TXXX", description, new String[0]);
}
int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding); int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
while (valueStartIndex < valueEndIndex) { while (valueStartIndex < valueEndIndex) {
String value = decodeStringIfValid(data, valueStartIndex, valueEndIndex, charset); String value = decodeStringIfValid(data, valueStartIndex, valueEndIndex, charset);
...@@ -496,6 +500,10 @@ public final class Id3Decoder extends SimpleMetadataDecoder { ...@@ -496,6 +500,10 @@ public final class Id3Decoder extends SimpleMetadataDecoder {
ArrayList<String> values = new ArrayList<>(); ArrayList<String> values = new ArrayList<>();
int valueStartIndex = 0; int valueStartIndex = 0;
if (valueStartIndex >= data.length) {
return new TextInformationFrame(id, null, new String[0]);
}
int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding); int valueEndIndex = indexOfTerminator(data, valueStartIndex, encoding);
while (valueStartIndex < valueEndIndex) { while (valueStartIndex < valueEndIndex) {
String value = decodeStringIfValid(data, valueStartIndex, valueEndIndex, charset); String value = decodeStringIfValid(data, valueStartIndex, valueEndIndex, charset);
......
...@@ -19,6 +19,7 @@ import static com.google.android.exoplayer2.util.Util.castNonNull; ...@@ -19,6 +19,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.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.MediaMetadata; import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
...@@ -36,17 +37,19 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -36,17 +37,19 @@ public final class TextInformationFrame extends Id3Frame {
@Deprecated @Deprecated
public final String value; public final String value;
@NonNull
public final String[] values; public final String[] values;
public TextInformationFrame(String id, @Nullable String description, String[] values) { public TextInformationFrame(String id, @Nullable String description, @NonNull String[] values) {
super(id); super(id);
if (values.length == 0) {
throw new IllegalArgumentException("A text information frame must have at least one value.");
}
this.description = description; this.description = description;
this.values = values; this.values = values;
this.value = values[0];
if (values.length > 0) {
this.value = values[0];
} else {
this.value = null;
}
} }
/** @deprecated Use {@code TextInformationFrame(String id, String description, String[] values} instead */ /** @deprecated Use {@code TextInformationFrame(String id, String description, String[] values} instead */
...@@ -58,8 +61,7 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -58,8 +61,7 @@ public final class TextInformationFrame extends Id3Frame {
/* package */ TextInformationFrame(Parcel in) { /* package */ TextInformationFrame(Parcel in) {
super(castNonNull(in.readString())); super(castNonNull(in.readString()));
description = in.readString(); description = in.readString();
values = new String[] {}; values = in.createStringArray();
in.readStringArray(values);
this.value = values[0]; this.value = values[0];
} }
...@@ -181,7 +183,7 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -181,7 +183,7 @@ public final class TextInformationFrame extends Id3Frame {
TextInformationFrame other = (TextInformationFrame) obj; TextInformationFrame other = (TextInformationFrame) obj;
return Util.areEqual(id, other.id) return Util.areEqual(id, other.id)
&& Util.areEqual(description, other.description) && Util.areEqual(description, other.description)
&& Util.areEqual(values, other.values); && Arrays.equals(values, other.values);
} }
@Override @Override
...@@ -195,7 +197,7 @@ public final class TextInformationFrame extends Id3Frame { ...@@ -195,7 +197,7 @@ public final class TextInformationFrame extends Id3Frame {
@Override @Override
public String toString() { public String toString() {
return id + ": description=" + description + ": values=" + String.join(MULTI_VALUE_DELIMITER, values); return id + ": description=" + description + ": value=" + String.join(MULTI_VALUE_DELIMITER, values);
} }
// Parcelable implementation. // Parcelable implementation.
......
...@@ -52,7 +52,7 @@ public final class Id3DecoderTest { ...@@ -52,7 +52,7 @@ public final class Id3DecoderTest {
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0); TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX"); assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEmpty(); assertThat(textInformationFrame.description).isEmpty();
assertThat(textInformationFrame.value).isEqualTo("mdialog_VINDICO1527664_start"); assertThat(textInformationFrame.values[0]).isEqualTo("mdialog_VINDICO1527664_start");
// Test UTF-16. // Test UTF-16.
rawId3 = rawId3 =
...@@ -67,7 +67,7 @@ public final class Id3DecoderTest { ...@@ -67,7 +67,7 @@ public final class Id3DecoderTest {
textInformationFrame = (TextInformationFrame) metadata.get(0); textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX"); assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEqualTo("Hello World"); assertThat(textInformationFrame.description).isEqualTo("Hello World");
assertThat(textInformationFrame.value).isEmpty(); assertThat(textInformationFrame.values).isEmpty();
// Test empty. // Test empty.
rawId3 = buildSingleFrameTag("TXXX", new byte[0]); rawId3 = buildSingleFrameTag("TXXX", new byte[0]);
...@@ -81,7 +81,7 @@ public final class Id3DecoderTest { ...@@ -81,7 +81,7 @@ public final class Id3DecoderTest {
textInformationFrame = (TextInformationFrame) metadata.get(0); textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TXXX"); assertThat(textInformationFrame.id).isEqualTo("TXXX");
assertThat(textInformationFrame.description).isEmpty(); assertThat(textInformationFrame.description).isEmpty();
assertThat(textInformationFrame.value).isEmpty(); assertThat(textInformationFrame.values).isEmpty();
} }
@Test @Test
...@@ -95,7 +95,8 @@ public final class Id3DecoderTest { ...@@ -95,7 +95,8 @@ public final class Id3DecoderTest {
TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0); TextInformationFrame textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TIT2"); assertThat(textInformationFrame.id).isEqualTo("TIT2");
assertThat(textInformationFrame.description).isNull(); assertThat(textInformationFrame.description).isNull();
assertThat(textInformationFrame.value).isEqualTo("Hello World"); assertThat(textInformationFrame.values.length).isEqualTo(1);
assertThat(textInformationFrame.values[0]).isEqualTo("Hello World");
// Test empty. // Test empty.
rawId3 = buildSingleFrameTag("TIT2", new byte[0]); rawId3 = buildSingleFrameTag("TIT2", new byte[0]);
...@@ -109,7 +110,7 @@ public final class Id3DecoderTest { ...@@ -109,7 +110,7 @@ public final class Id3DecoderTest {
textInformationFrame = (TextInformationFrame) metadata.get(0); textInformationFrame = (TextInformationFrame) metadata.get(0);
assertThat(textInformationFrame.id).isEqualTo("TIT2"); assertThat(textInformationFrame.id).isEqualTo("TIT2");
assertThat(textInformationFrame.description).isNull(); assertThat(textInformationFrame.description).isNull();
assertThat(textInformationFrame.value).isEmpty(); assertThat(textInformationFrame.values).isEmpty();
} }
@Test @Test
......
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