mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +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.text.style.UnderlineSpan;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import com.google.android.exoplayer2.text.Cue;
|
import com.google.android.exoplayer2.text.Cue;
|
||||||
|
import com.google.android.exoplayer2.util.ColorParser;
|
||||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -380,6 +381,8 @@ public final class WebvttCueParser {
|
|||||||
text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
text.setSpan(new UnderlineSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
break;
|
break;
|
||||||
case TAG_CLASS:
|
case TAG_CLASS:
|
||||||
|
applySupportedClasses(text, startTag.classes, start, end);
|
||||||
|
break;
|
||||||
case TAG_LANG:
|
case TAG_LANG:
|
||||||
case TAG_VOICE:
|
case TAG_VOICE:
|
||||||
case "": // Case of the "whole cue" virtual tag.
|
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,
|
private static void applyStyleToText(SpannableStringBuilder spannedText, WebvttCssStyle style,
|
||||||
int start, int end) {
|
int start, int end) {
|
||||||
if (style == null) {
|
if (style == null) {
|
||||||
|
@ -43,6 +43,10 @@ public final class ColorParser {
|
|||||||
|
|
||||||
private static final Map<String, Integer> COLOR_MAP;
|
private static final Map<String, Integer> COLOR_MAP;
|
||||||
|
|
||||||
|
public static boolean isNamedColor(String expression) {
|
||||||
|
return COLOR_MAP.containsKey(expression);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a TTML color expression.
|
* Parses a TTML color expression.
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user