Skip to content
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

[video_player] Ensures autoplay is false on the web. #4961

Merged
merged 3 commits into from
Sep 26, 2023
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
5 changes: 5 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.1.1

* Ensures that the `autoplay` attribute of the underlying video element is set
to **false**.

## 2.1.0

* Adds web options to customize the control list and context menu display.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ void main() {

expect(video.controls, isFalse,
reason: 'Video is controlled through code');
expect(video.getAttribute('autoplay'), 'false',
reason: 'Cannot autoplay on the web');
expect(video.autoplay, isFalse,
reason: 'autoplay attribute on HTMLVideoElement MUST be false');
// see: https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
Copy link
Contributor

Choose a reason for hiding this comment

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

Ugh, I had forgotten about this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this is a doozy of a feature :)

expect(video.getAttribute('autoplay'), isNull,
reason: 'autoplay attribute on video tag must NOT be set');
expect(video.getAttribute('playsinline'), 'true',
reason: 'Needed by safari iOS');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ class VideoPlayer {
..autoplay = false
..controls = false;

// Allows Safari iOS to play the video inline
// Allows Safari iOS to play the video inline.
//
// This property is not exposed through dart:html so we use the
// HTML Boolean attribute form (when present with any value => true)
// See: https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
_videoElement.setAttribute('playsinline', 'true');

// Set autoplay to false since most browsers won't autoplay a video unless it is muted
_videoElement.setAttribute('autoplay', 'false');

_videoElement.onCanPlay.listen((dynamic _) {
if (!_isInitialized) {
_isInitialized = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player_web
description: Web platform implementation of video_player.
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
version: 2.1.0
version: 2.1.1

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down