Skip to content

[video_player] Fixes mechanism to detect identifier in multiline WebVTT captions #8555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +169 to +170
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting choice

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just copied it from the test above 😅


''';

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