From 767c7ab1692d13cafac7251bed44ccbd0d411c0f Mon Sep 17 00:00:00 2001 From: aquilescanta Date: Tue, 12 Apr 2016 07:02:45 -0700 Subject: [PATCH] Fixed id referencing in WebVTT CSS styling In CSS, ids are references using #. The absence of # references elements. NOTE: If the id of a cue was "1", we support its reference with ::cue(#1). In CSS, however, this is not valid, and the number should be escaped with \3 as in ::cue(\31). We still do not use number escaping (and I doubt whether we should at some point). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=119634708 --- library/src/androidTest/assets/webvtt/with_css_styles | 6 +++--- .../com/google/android/exoplayer/text/webvtt/WebvttCue.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/library/src/androidTest/assets/webvtt/with_css_styles b/library/src/androidTest/assets/webvtt/with_css_styles index ec7caace6d..c7fcc4217c 100644 --- a/library/src/androidTest/assets/webvtt/with_css_styles +++ b/library/src/androidTest/assets/webvtt/with_css_styles @@ -10,14 +10,14 @@ STYLE NOTE comment blocks can be used between style blocks. STYLE -::cue(2) { +::cue(#id2) { color: peachpuff; } -1 +id1 00:00.000 --> 00:01.234 This is the first subtitle. -2 +id2 00:02.345 --> 00:03.456 This is the second subtitle. diff --git a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttCue.java b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttCue.java index f2ea42fded..bb0d87b7ec 100644 --- a/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttCue.java +++ b/library/src/main/java/com/google/android/exoplayer/text/webvtt/WebvttCue.java @@ -41,7 +41,8 @@ import java.util.Map; /* package */ final class WebvttCue extends Cue { public static final String UNIVERSAL_CUE_ID = ""; - + public static final String CUE_ID_PREFIX = "#"; + public final String id; public final long startTime; public final long endTime; @@ -122,7 +123,7 @@ import java.util.Map; public WebvttCue build(Map styleMap) { // TODO: Add support for inner spans. maybeApplyStyleToText(styleMap.get(UNIVERSAL_CUE_ID), 0, text.length()); - maybeApplyStyleToText(styleMap.get(id), 0, text.length()); + maybeApplyStyleToText(styleMap.get(CUE_ID_PREFIX + id), 0, text.length()); if (position != Cue.DIMEN_UNSET && positionAnchor == Cue.TYPE_UNSET) { derivePositionAnchorFromAlignment(); }