diff --git a/library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java b/library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java index 80ebecdc0e..4ef78ffb87 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/text/webvtt/WebvttCueParser.java @@ -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) { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java b/library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java index a9df80e9fe..87202663b8 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/util/ColorParser.java @@ -43,6 +43,10 @@ public final class ColorParser { private static final Map COLOR_MAP; + public static boolean isNamedColor(String expression) { + return COLOR_MAP.containsKey(expression); + } + /** * Parses a TTML color expression. *