From 8b2af1244725b8d600c3f5ea2cceb4504728c7d9 Mon Sep 17 00:00:00 2001 From: Rik Heijdens Date: Wed, 24 Aug 2016 14:58:08 +0200 Subject: [PATCH] Discard spans after seeking Discard any spans that should not be applied because they don't belong to what's in the current CC buffer. --- .../android/exoplayer2/text/eia608/Eia608Decoder.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java index c54cc2ef5e..ecd2c766c4 100644 --- a/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java +++ b/library/src/main/java/com/google/android/exoplayer2/text/eia608/Eia608Decoder.java @@ -656,9 +656,13 @@ public final class Eia608Decoder implements SubtitleDecoder { } for (Integer startIndex : captionStyles.keySet()) { - CharacterStyle captionStyle = captionStyles.get(startIndex); - captionStringBuilder.setSpan(captionStyle, startIndex, - captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + // There may be cases, e.g. when seeking where the startIndex becomes greater + // than what is actually in the string builder, in that case, just discard the span. + if (startIndex < captionStringBuilder.length()) { + CharacterStyle captionStyle = captionStyles.get(startIndex); + captionStringBuilder.setSpan(captionStyle, startIndex, + captionStringBuilder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + } captionStyles.remove(startIndex); } }