Skip to content

Commit ed4e86d

Browse files
authored
[video_player] Ensures autoplay is false on the web. (#4961)
### Description This PR changes the initialization of the `video` element used by the web implementation of the video_player plugin to **ensure the `autoplay` attribute is set to _**false**_**, as expected by the code. ### Issues * Fixes flutter/flutter#135194 * ~~May be the root cause of flutter/flutter#130147~~ (it isn't, I've seen the integration test failing again)
1 parent a9a8cc6 commit ed4e86d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

packages/video_player/video_player_web/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.1
2+
3+
* Ensures that the `autoplay` attribute of the underlying video element is set
4+
to **false**.
5+
16
## 2.1.0
27

38
* Adds web options to customize the control list and context menu display.

packages/video_player/video_player_web/example/integration_test/video_player_test.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ void main() {
3131

3232
expect(video.controls, isFalse,
3333
reason: 'Video is controlled through code');
34-
expect(video.getAttribute('autoplay'), 'false',
35-
reason: 'Cannot autoplay on the web');
34+
expect(video.autoplay, isFalse,
35+
reason: 'autoplay attribute on HTMLVideoElement MUST be false');
36+
// see: https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML
37+
expect(video.getAttribute('autoplay'), isNull,
38+
reason: 'autoplay attribute on video tag must NOT be set');
3639
expect(video.getAttribute('playsinline'), 'true',
3740
reason: 'Needed by safari iOS');
3841
});

packages/video_player/video_player_web/lib/src/video_player.dart

+5-4
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ class VideoPlayer {
6363
..autoplay = false
6464
..controls = false;
6565

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

69-
// Set autoplay to false since most browsers won't autoplay a video unless it is muted
70-
_videoElement.setAttribute('autoplay', 'false');
71-
7273
_videoElement.onCanPlay.listen((dynamic _) {
7374
if (!_isInitialized) {
7475
_isInitialized = true;

packages/video_player/video_player_web/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_web
22
description: Web platform implementation of video_player.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.1.0
5+
version: 2.1.1
66

77
environment:
88
sdk: ">=3.1.0 <4.0.0"

0 commit comments

Comments
 (0)