-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Webvtt subtitles class colors #4178
Changes from 2 commits
117239a
e99a7f6
fc5dbfe
987939d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import com.google.android.exoplayer2.text.span.HorizontalTextInVerticalContextSpan; | ||
import com.google.android.exoplayer2.text.span.RubySpan; | ||
import com.google.android.exoplayer2.util.Assertions; | ||
import com.google.android.exoplayer2.util.ColorParser; | ||
import com.google.android.exoplayer2.util.Log; | ||
import com.google.android.exoplayer2.util.ParsableByteArray; | ||
import com.google.android.exoplayer2.util.Util; | ||
|
@@ -514,6 +515,8 @@ private static void applySpansForTag( | |
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. | ||
|
@@ -529,6 +532,16 @@ private static void applySpansForTag( | |
} | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is neat code re-use, but because the WebVTT list is so much shorter than the list of CSS colors I think it would be clearer to explicitly list the WebVTT default colors. Otherwise if someone defines a custom class called So I think a That will also make adding background color support less 'different' - we can just add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, I'll take a look and update this soon There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated the strategy by adding the two maps (adds support for background too) in |
||
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) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests to
WebvttCueParserTest
for this?