Rename VTT voice span speakerName to name
This commit is contained in:
parent
ce52fc77ec
commit
24bbe6d921
@ -21,8 +21,6 @@ import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import android.os.Bundle;
|
||||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.common.util.Util;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A span representing a speaker.
|
||||
@ -33,22 +31,22 @@ import java.util.Set;
|
||||
@UnstableApi
|
||||
public final class VoiceSpan {
|
||||
|
||||
/** The speaker name. */
|
||||
public final String speakerName;
|
||||
/** The voice name. */
|
||||
public final String name;
|
||||
|
||||
private static final String FIELD_NAME = Util.intToStringMaxRadix(0);
|
||||
|
||||
public VoiceSpan(String speakerName) {
|
||||
this.speakerName = speakerName;
|
||||
public VoiceSpan(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Bundle toBundle() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FIELD_NAME, speakerName);
|
||||
bundle.putString(FIELD_NAME, name);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
public static VoiceSpan fromBundle(Bundle bundle) {
|
||||
return new VoiceSpan(/* speakerName = */ checkNotNull(bundle.getString(FIELD_NAME)));
|
||||
return new VoiceSpan(/* name = */ checkNotNull(bundle.getString(FIELD_NAME)));
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class CustomCueBundlerTest {
|
||||
.hasVoiceSpanBetween(
|
||||
ALL_SPANS_TO_START_END_INDEX.get(VOICE_SPAN).first,
|
||||
ALL_SPANS_TO_START_END_INDEX.get(VOICE_SPAN).second)
|
||||
.withSpeakerName(VOICE_SPAN.speakerName);
|
||||
.withName(VOICE_SPAN.name);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -249,7 +249,7 @@ public final class WebvttCueParserTest {
|
||||
assertThat(text.toString()).isEqualTo("Text with a single voice span");
|
||||
assertThat(text)
|
||||
.hasVoiceSpanBetween(0, "Text with a single voice span".length())
|
||||
.withSpeakerName("");
|
||||
.withName("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -259,7 +259,7 @@ public final class WebvttCueParserTest {
|
||||
assertThat(text.toString()).isEqualTo("Text with a single voice span");
|
||||
assertThat(text)
|
||||
.hasVoiceSpanBetween(0, "Text with a single voice span".length())
|
||||
.withSpeakerName("Esme");
|
||||
.withName("Esme");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -269,7 +269,7 @@ public final class WebvttCueParserTest {
|
||||
assertThat(text.toString()).isEqualTo("Text with a single voice span");
|
||||
assertThat(text)
|
||||
.hasVoiceSpanBetween(0, "Text with a single voice span".length())
|
||||
.withSpeakerName("");
|
||||
.withName("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -279,7 +279,7 @@ public final class WebvttCueParserTest {
|
||||
assertThat(text.toString()).isEqualTo("Text with a single voice span");
|
||||
assertThat(text)
|
||||
.hasVoiceSpanBetween(0, "Text with a single voice span".length())
|
||||
.withSpeakerName("Esme");
|
||||
.withName("Esme");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -287,10 +287,10 @@ public final class WebvttCueParserTest {
|
||||
Spanned text = parseCueText("<v.loud Esme>Text with </v><v.quiet Mary>multiple voice spans");
|
||||
|
||||
assertThat(text.toString()).isEqualTo("Text with multiple voice spans");
|
||||
assertThat(text).hasVoiceSpanBetween(0, "Text with ".length()).withSpeakerName("Esme");
|
||||
assertThat(text).hasVoiceSpanBetween(0, "Text with ".length()).withName("Esme");
|
||||
assertThat(text)
|
||||
.hasVoiceSpanBetween("Text with ".length(), "Text with multiple voice spans".length())
|
||||
.withSpeakerName("Mary");
|
||||
.withName("Mary");
|
||||
}
|
||||
|
||||
private static Spanned parseCueText(String string) {
|
||||
|
@ -54,7 +54,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||
|
||||
/** A Truth {@link Subject} for assertions on {@link Spanned} instances containing text styling. */
|
||||
@ -661,8 +660,8 @@ public final class SpannedSubject extends Subject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that the subject has no {@link VoiceSpan}s on any of the text
|
||||
* between {@code start} and {@code end}.
|
||||
* Checks that the subject has no {@link VoiceSpan}s on any of the text between {@code start} and
|
||||
* {@code end}.
|
||||
*
|
||||
* <p>This fails even if the start and end indexes don't exactly match.
|
||||
*
|
||||
@ -1320,10 +1319,11 @@ public final class SpannedSubject extends Subject {
|
||||
* @param name The expected name of the voice.
|
||||
* @return A {@link AndSpanFlags} object for optional additional assertions on the flags.
|
||||
*/
|
||||
AndSpanFlags withSpeakerName(String name);
|
||||
AndSpanFlags withName(String name);
|
||||
}
|
||||
|
||||
private static final VoiceText ALREADY_FAILED_WITH_NAME_AND_CLASSES = (name) -> ALREADY_FAILED_AND_FLAGS;
|
||||
private static final VoiceText ALREADY_FAILED_WITH_NAME_AND_CLASSES =
|
||||
(name) -> ALREADY_FAILED_AND_FLAGS;
|
||||
|
||||
private static Factory<VoiceSpanSubject, List<VoiceSpan>> voiceSpanSubjects(
|
||||
Spanned actualSpanned) {
|
||||
@ -1337,36 +1337,32 @@ public final class SpannedSubject extends Subject {
|
||||
private final Spanned actualSpanned;
|
||||
|
||||
private VoiceSpanSubject(
|
||||
FailureMetadata metadata,
|
||||
@Nullable List<VoiceSpan> actualSpans,
|
||||
Spanned actualSpanned) {
|
||||
FailureMetadata metadata, @Nullable List<VoiceSpan> actualSpans, Spanned actualSpanned) {
|
||||
super(metadata, actualSpans);
|
||||
this.actualSpans = actualSpans;
|
||||
this.actualSpanned = actualSpanned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AndSpanFlags withSpeakerName(String name) {
|
||||
public AndSpanFlags withName(String name) {
|
||||
List<Integer> matchingSpanFlags = new ArrayList<>();
|
||||
List<SpeakerName> voiceSpeakerName = new ArrayList<>();
|
||||
List<Name> voiceName = new ArrayList<>();
|
||||
for (VoiceSpan span : checkNotNull(actualSpans)) {
|
||||
voiceSpeakerNameAndClasses.add(new SpeakerName(span.speakerName));
|
||||
if (span.speakerName.equals(name)) {
|
||||
voiceName.add(new Name(span.name));
|
||||
if (span.name.equals(name)) {
|
||||
matchingSpanFlags.add(actualSpanned.getSpanFlags(span));
|
||||
}
|
||||
}
|
||||
check("voiceSpeakerName")
|
||||
.that(voiceSpeakerNameAndClasses)
|
||||
.containsExactly(new SpeakerName(name));
|
||||
check("voiceName").that(voiceName).containsExactly(new Name(name));
|
||||
return check("flags").about(spanFlags()).that(matchingSpanFlags);
|
||||
}
|
||||
|
||||
private static final class SpeakerName {
|
||||
private static final class Name {
|
||||
|
||||
private final String speakerName;
|
||||
private final String name;
|
||||
|
||||
private SpeakerName(String name) {
|
||||
this.speakerName = name;
|
||||
private Name(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1378,18 +1374,18 @@ public final class SpannedSubject extends Subject {
|
||||
return false;
|
||||
}
|
||||
|
||||
SpeakerName that = (SpeakerName) o;
|
||||
Name that = (Name) o;
|
||||
return name.equals(that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(speakerName);
|
||||
return Objects.hash(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("{speakerName=%s}", speakerName);
|
||||
return String.format("{name=%s}", name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ import androidx.media3.test.utils.truth.SpannedSubject.AndSpanFlags;
|
||||
import androidx.media3.test.utils.truth.SpannedSubject.WithSpanFlags;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.google.common.truth.ExpectFailure;
|
||||
import java.util.Set;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@ -913,7 +912,7 @@ public class SpannedSubjectTest {
|
||||
|
||||
assertThat(spannable)
|
||||
.hasVoiceSpanBetween(SPAN_START, SPAN_END)
|
||||
.withSpeakerName("speaker")
|
||||
.withName("speaker")
|
||||
.andFlags(Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
@ -925,7 +924,7 @@ public class SpannedSubjectTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voiceSpan_wrongSpeakerName() {
|
||||
public void voiceSpan_wrongName() {
|
||||
SpannableString spannable = createSpannable(new VoiceSpan("speaker"));
|
||||
|
||||
AssertionError expected =
|
||||
@ -934,11 +933,11 @@ public class SpannedSubjectTest {
|
||||
whenTesting
|
||||
.that(spannable)
|
||||
.hasVoiceSpanBetween(SPAN_START, SPAN_END)
|
||||
.withSpeakerName("different speaker"));
|
||||
.withName("different speaker"));
|
||||
|
||||
assertThat(expected).factValue("value of").contains("voiceSpeakerName");
|
||||
assertThat(expected).factValue("expected").contains("speakerName=different speaker");
|
||||
assertThat(expected).factValue("but was").contains("speakerName=speaker");
|
||||
assertThat(expected).factValue("value of").contains("voiceName");
|
||||
assertThat(expected).factValue("expected").contains("name=different speaker");
|
||||
assertThat(expected).factValue("but was").contains("name=speaker");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -948,7 +947,7 @@ public class SpannedSubjectTest {
|
||||
(subject, start, end) ->
|
||||
subject
|
||||
.hasVoiceSpanBetween(start, end)
|
||||
.withSpeakerName("speaker"));
|
||||
.withName("speaker"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user