-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Interrupt autoplay when video element becomes invisible #2324
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
Conversation
xxyzzzq
commented
Feb 6, 2017
- Allow the user agent to interrupt an autoplaying video when it becomes invisible.
- Renamed the confusing name "autoplaying flag" to "autoplay on demand flag".
|
@foolip @mounirlamouri PTAL |
|
This is also changing the behavior when a video starts autoplaying to no longer set the flag to |
|
2e0317c to
726b535
Compare
Yes, I feel the original flag "autoplaying flag" has some inconsistencies, so it is hard to tell what it really mean. This is why I'm changing the name to "autoplay on demand flag" to "the element is in the autoplaying stage", so the user agent can autoplay it if they want if the flag is true. If we keep the old behavior and set the flag to |
Yes, Safari on iOS already does this (using an equivalent implementation). So I think websites who care about the autoplay behavior should already know it.
Yes, it would be nice to have this. However we are targeting the |
source
Outdated
| <li><span>Notify about playing</span> for the element.</li> | ||
|
|
||
| <li>Set the <span>autoplaying flag</span> to false.</li> | ||
| <li>Optionally, if the substeps are triggered when a <code>video</code> element <span |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an editorial nit, I think this would be better as a separate paragraph (stating "when the element no longer..." instead of "wait until the element no longer...") introducing a second set of substeps, instead of as a step inside the autoplay substeps. Then you don't need to define the "substeps for interrupting autoplay" either (unless you were planning on using those from another spec?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. It's a bit hard to rephrase without the substep set names as they reference each other (run the other set after one set is finished). However I managed to do it. PTAL
domenic
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, although I'd like @zcorpan's signoff for media stuff if he has time.
foolip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we should make this change, just a bit of tinkering needed.
source
Outdated
|
|
||
| <ol> | ||
|
|
||
| <li>Set the <code data-x="dom-media-paused">paused</code> attribute to true.</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should use https://html.spec.whatwg.org/multipage/embedded-content.html#internal-pause-steps, but I guess that setting the "autoplay on demand flag" to false would prevent autoplay the next time the video intersects the viewport? It'd be fine to just say "invoke the internal pause steps and set the autoplay on demand flag to false" instead.
I think it would be good to point out that the steps for playing and pausing can be triggered many times. Because this inside an algorithm, my default assumption would be that one never jumps to an earlier step implicitly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, setting the paused attribute is a bit weird as it is intended to be used for reflecting instead of controlling the playback state.
It'd be fine to just say "invoke the internal pause steps and set the autoplay on demand flag to false" instead.
Did you mean "invoke the internal pause steps and set the autoplay on demand flag to true"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes, true is the default state :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
source
Outdated
| <div w-nodev> | ||
|
|
||
| <p>All <span data-x="media element">media elements</span> have an <dfn>autoplaying flag</dfn>, | ||
| <p>All <span data-x="media element">media elements</span> have an <dfn>autoplay on demand flag</dfn>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old name was pretty bad, so allow me to bikeshed a little bit. In this context, I'd associate "on demand" with a user doing the demanding or perhaps video on demand as opposed to live. To call it "autoplay eligibility flag" would be an accurate and boring name. That's the best I can come up with, any other ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will be a bit confusing with the definition of "eligible for autoplay". Maybe name it "autoplay stage flag"? which is always true after loading and before the user explicitly call play() or pause(). The UA can autoplay at will if the flag is true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, one would have to pay attention to not confuse "eligible for autoplay" with the raw value of the flag. "The UA can autoplay at will if the flag is true" is precisely it, so maybe the "can autoplay flag"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SGTM, will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
Safari has an equivalent implementation. +@jernoble to look at this change and see if he's okay. |
|
@foolip PTAL |
…ps can be triggered multiple times
| the viewport</span> and, if the element is still <span>eligible for autoplay</span>, run the | ||
| substeps above. Optionally, when the element stops <span data-x="intersect the | ||
| viewport">intersecting the viewport</span>, and if the <span>can autoplay flag</span> is still | ||
| true and the <code data-x="attr-media-autoplay">autoplay</code> attribute is still specified, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@foolip I tend to remove the paused attribute from the "eligible for autoplay", so we can use:
- Eligible for autoplay and
pausedattribute is true for starting autoplay - Eligible for autoplay and
pausedattribute is false for pausing autoplay
Does it sound good?
foolip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few minor things with punctuation and moved+clarified the note about multiple play/pause. @xxyzzzq, can you check if it's OK before merging?
|
I have filed web-platform-tests/wpt#4772 to track the fact that it's not possible to write shared tests for this. |
|
Ping @jernoble to check if this is close enough to what WebKit does. |
|
@foolip LGTM. Thanks for the fixes 👍 |
|
@foolip, AFAICT, this is close enough to what WebKit does on iOS. |
|
Implementation bugs:
|
In this CL, when a muted video is autoplaying from attribute, we pause it when it comes off screen. Intent to implement and ship: https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/UtFM-kndhaI Spec PR: whatwg/html#2324 BUG=683141 Review-Url: https://codereview.chromium.org/2654123002 Cr-Commit-Position: refs/heads/master@{#450707}
|
I think we should also consider whether the video is audible or not, because it's annoying that the audio track was also be paused when the video became invisible. |