Skip to content

[video_player] Add html 5 video poster support (thumbnail) as a VideoPlayerWebOptions #8940

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions packages/video_player/video_player/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ dev_dependencies:
topics:
- video
- video-player
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}
video_player_web: {path: ../../../packages/video_player/video_player_web}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 6.4.0

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

## 6.3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ class VideoPlayerWebOptions {
this.controls = const VideoPlayerWebOptionsControls.disabled(),
this.allowContextMenu = true,
this.allowRemotePlayback = true,
this.poster,
});

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

/// Whether remote playback is allowed
final bool allowRemotePlayback;

/// The URL of the poster image to be displayed before the video starts
final Uri? poster;
}

/// [VideoPlayerWebOptions] can be used to set how control options are displayed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 6.3.0
version: 6.4.0

environment:
sdk: ^3.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,24 @@ void main() {
expect(options.allowRemotePlayback, isTrue);
},
);

group('VideoPlayerOptions poster', () {
test(
'defaults to null',
() {
const VideoPlayerWebOptions options = VideoPlayerWebOptions();
expect(options.poster, null);
},
);

test(
'with a value',
() {
final VideoPlayerWebOptions options = VideoPlayerWebOptions(
poster: Uri.parse('https://example.com/poster.jpg'),
);
expect(options.poster, Uri.parse('https://example.com/poster.jpg'));
},
);
});
}
3 changes: 2 additions & 1 deletion packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 2.3.6

* Add html 5 video poster support as a VideoPlayerWebOptions.
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.

## 2.3.5
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../../packages/video_player/video_player_platform_interface}
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class VideoPlayer {
if (!options.allowRemotePlayback) {
_videoElement.disableRemotePlayback = true;
}

if (options.poster != null) {
_videoElement.poster = options.poster!.toString();
}
}

void _resetOptions() {
Expand Down
6 changes: 5 additions & 1 deletion packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies:
sdk: flutter
flutter_web_plugins:
sdk: flutter
video_player_platform_interface: ^6.3.0
video_player_platform_interface: ^6.3.1
web: ">=0.5.1 <2.0.0"

dev_dependencies:
Expand All @@ -31,3 +31,7 @@ dev_dependencies:
topics:
- video
- video-player
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}