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.
This commit is contained in:
Rik Heijdens 2016-08-24 14:58:08 +02:00
parent 43e6e16168
commit 8b2af12447

View file

@ -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);
}
}