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