Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
[video_player] Ensures autoplay is false on web.
  • Loading branch information
ditman committed Sep 21, 2023
commit 52c35b43c2a3526feb9abfa3f8a885ef8183d6b4
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
Collaborator

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 @@ -66,8 +66,8 @@ class VideoPlayer {
// Allows Safari iOS to play the video inline
_videoElement.setAttribute('playsinline', 'true');

// Set autoplay to false since most browsers won't autoplay a video unless it is muted
_videoElement.setAttribute('autoplay', 'false');
// Ensure autoplay is not set through the DOM!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this mean we should also remove line 63, or is that doing something different? I'm not clear on what exactly the HTML wrapper class properties do.

Copy link
Member Author

@ditman ditman Sep 21, 2023

Choose a reason for hiding this comment

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

At least in chrome, they're kept in sync (I'm going to assume this is standard behavior), so we could do either:

Screenshot 2023-09-21 at 11 39 42 AM

(Vanilla-JS above)

Copy link
Member Author

@ditman ditman Sep 21, 2023

Choose a reason for hiding this comment

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

I removed the removeAttribute call, which is redundant with line 63. Left the check in the tests, which should pass anyway. I also documented why we need to do setAttribute on the "playsinline" property. (Core video_player integration tests still pass normally on the web.)

_videoElement.removeAttribute('autoplay');

_videoElement.onCanPlay.listen((dynamic _) {
if (!_isInitialized) {
Expand Down