Skip to content

Commit 5eb36be

Browse files
authored
[video_player] Add poster attribute for html video tag in video_player_platform_interface (#8979)
This PR adds support for the poster attribute on web by introducing a poster field in VideoPlayerWebOptions. It allows setting a thumbnail image for videos using the native HTML5 poster property, improving the out-of-the-box web experience. This PR is is the changes to platform_interface for this [one](#8940) Solve this issue: flutter/flutter#166232 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent d28ee59 commit 5eb36be

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 6.4.0
22

3+
* Adds HTML5 video poster support as a VideoPlayerWebOptions.
34
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
45

56
## 6.3.0

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ class VideoPlayerWebOptions {
429429
this.controls = const VideoPlayerWebOptionsControls.disabled(),
430430
this.allowContextMenu = true,
431431
this.allowRemotePlayback = true,
432+
this.poster,
432433
});
433434

434435
/// Additional settings for how control options are displayed
@@ -439,6 +440,9 @@ class VideoPlayerWebOptions {
439440

440441
/// Whether remote playback is allowed
441442
final bool allowRemotePlayback;
443+
444+
/// The URL of the poster image to be displayed before the video starts
445+
final Uri? poster;
442446
}
443447

444448
/// [VideoPlayerWebOptions] can be used to set how control options are displayed

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.3.0
7+
version: 6.4.0
88

99
environment:
1010
sdk: ^3.6.0

packages/video_player/video_player_platform_interface/test/video_player_web_options_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,24 @@ void main() {
2929
expect(options.allowRemotePlayback, isTrue);
3030
},
3131
);
32+
33+
group('VideoPlayerOptions poster', () {
34+
test(
35+
'defaults to null',
36+
() {
37+
const VideoPlayerWebOptions options = VideoPlayerWebOptions();
38+
expect(options.poster, null);
39+
},
40+
);
41+
42+
test(
43+
'with a value',
44+
() {
45+
final VideoPlayerWebOptions options = VideoPlayerWebOptions(
46+
poster: Uri.parse('https://example.com/poster.jpg'),
47+
);
48+
expect(options.poster, Uri.parse('https://example.com/poster.jpg'));
49+
},
50+
);
51+
});
3252
}

0 commit comments

Comments
 (0)