mirror of
https://github.com/androidx/media.git
synced 2025-05-17 04:29:55 +08:00
Apply ColorSpan if subtitle cue startTag contains color class
This commit is contained in:
parent
18b1ec7a2f
commit
117239a709
@ -33,6 +33,7 @@ import android.text.style.TypefaceSpan;
|
||||
import android.text.style.UnderlineSpan;
|
||||
import android.util.Log;
|
||||
import com.google.android.exoplayer2.text.Cue;
|
||||
import com.google.android.exoplayer2.util.ColorParser;
|
||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@ -380,6 +381,8 @@ public final class WebvttCueParser {
|
||||
text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
break;
|
||||
case TAG_CLASS:
|
||||
applySupportedClasses(text, startTag.classes, start, end);
|
||||
break;
|
||||
case TAG_LANG:
|
||||
case TAG_VOICE:
|
||||
case "": // Case of the "whole cue" virtual tag.
|
||||
@ -395,6 +398,16 @@ public final class WebvttCueParser {
|
||||
}
|
||||
}
|
||||
|
||||
private static void applySupportedClasses(SpannableStringBuilder text, String[] classes,
|
||||
int start, int end) {
|
||||
for (String className : classes) {
|
||||
if (ColorParser.isNamedColor(className)) {
|
||||
int color = ColorParser.parseCssColor(className);
|
||||
text.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyStyleToText(SpannableStringBuilder spannedText, WebvttCssStyle style,
|
||||
int start, int end) {
|
||||
if (style == null) {
|
||||
|
@ -43,6 +43,10 @@ public final class ColorParser {
|
||||
|
||||
private static final Map<String, Integer> COLOR_MAP;
|
||||
|
||||
public static boolean isNamedColor(String expression) {
|
||||
return COLOR_MAP.containsKey(expression);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a TTML color expression.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user