Skip to content

Commit

Permalink
Strip trailing newline from WebVTT subtitles.
Browse files Browse the repository at this point in the history
  • Loading branch information
ojw28 committed Oct 1, 2014
1 parent 9fc963a commit ea1ab67
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@ public long getLastEventTime() {

@Override
public String getText(long timeUs) {
StringBuilder subtitleStringBuilder = new StringBuilder();
StringBuilder stringBuilder = new StringBuilder();

for (int i = 0; i < cueTimesUs.length; i += 2) {
if ((cueTimesUs[i] <= timeUs) && (timeUs < cueTimesUs[i + 1])) {
subtitleStringBuilder.append(cueText[i / 2]);
stringBuilder.append(cueText[i / 2]);
}
}

return (subtitleStringBuilder.length() > 0) ? subtitleStringBuilder.toString() : null;
int stringLength = stringBuilder.length();
if (stringLength > 0 && stringBuilder.charAt(stringLength - 1) == '\n') {
// Adjust the length to remove the trailing newline character.
stringLength -= 1;
}

return stringLength == 0 ? null : stringBuilder.substring(0, stringLength);
}

}

0 comments on commit ea1ab67

Please sign in to comment.