Skip to content

Commit

Permalink
[video_player] Fixes mechanism to detect identifier in multiline WebV…
Browse files Browse the repository at this point in the history
…TT captions (#8555)

In order to play WebVTT captions which include multiple lines the detection must be changed, as captions don't necessarily have an identifier, when they are longer than two lines.
  • Loading branch information
Gustl22 authored Feb 21, 2025
1 parent 5a721da commit a135dc6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/video_player/video_player/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 2.9.3

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Fixes mechanism to detect identifier in multi-line WebVTT captions.

## 2.9.2

Expand Down
5 changes: 3 additions & 2 deletions packages/video_player/video_player/lib/src/web_vtt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ List<Caption> _parseCaptionsFromWebVTTString(String file) {
continue;
}

// Caption has header
final bool hasHeader = captionLines.length > 2;
// Caption has header / identifier
// See: https://www.w3.org/TR/webvtt1/#webvtt-cue-identifier for valid cue identifier
final bool hasHeader = !captionLines[0].contains(_webVTTArrow);
if (hasHeader) {
final int? tryParseCaptionNumber = int.tryParse(captionLines[0]);
if (tryParseCaptionNumber != null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
widgets on Android, iOS, and web.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.9.2
version: 2.9.3

environment:
sdk: ^3.4.0
Expand Down
24 changes: 24 additions & 0 deletions packages/video_player/video_player/test/web_vtt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ void main() {
parsedFile = WebVTTCaptionFile(_valid_vtt_with_multiline);
expect(parsedFile.captions.length, 1);

expect(parsedFile.captions[0].number, 2);
expect(parsedFile.captions[0].start,
const Duration(seconds: 2, milliseconds: 800));
expect(parsedFile.captions[0].end,
const Duration(seconds: 3, milliseconds: 283));
expect(parsedFile.captions[0].text,
'— It will perforate your stomach.\n— You could die.');
});

test('with Multiline without identifier', () {
parsedFile =
WebVTTCaptionFile(_valid_vtt_with_multiline_without_identifier);
expect(parsedFile.captions.length, 1);

expect(parsedFile.captions[0].number, 1);
expect(parsedFile.captions[0].start,
const Duration(seconds: 2, milliseconds: 800));
expect(parsedFile.captions[0].end,
Expand Down Expand Up @@ -147,6 +162,15 @@ WEBVTT
''';

const String _valid_vtt_with_multiline_without_identifier = '''
WEBVTT
00:02.800 --> 00:03.283
— It will perforate your stomach.
— You could die.
''';

/// See https://www.w3.org/TR/webvtt1/#styling
const String _valid_vtt_with_styles = '''
WEBVTT
Expand Down

0 comments on commit a135dc6

Please sign in to comment.