-
Notifications
You must be signed in to change notification settings - Fork 7
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
The final decision of autoplay detection API name #12
Comments
@padenot would you mind to help me loop related people into this discussion? Thank you. |
Welcome @alastor0325, and thank you helping with editing the spec. If you haven't done so already, please create a W3C account, associate it with your GitHub account, and join the Media WG here. Looking at the people involved in the early discussion who are still active in the group, I recommend @beaufortfrancois and @jernoble as initial contacts. |
@alastor0325 We discussed briefly on the Media WG call today, @dalecurtis is the person to contact at Google for now. |
From the Google side, since we proposed it, we're happy with the existing names. We don't have a strong attachment though, so whatever gains consensus sgtm. |
canXXX() methods matches the existing HTMLMediaElement style FWIW. |
My main concern of returning a boolean on the media element API is that returned information might not be enough for web developers to make the decision. For instance, when
If we provide detailed information on the media element API as well, then we can achieve the same goal by only using one API.
WDYT @dalecurtis? |
autoplayPolicy only won't be misleading, but I'm unclear how the API is supposed to interact with user gestures. I.e., the 'do some stuffs here' section :) Are we solving the desired use cases if we only provide the policy value? |
As a player developer, one of the main things I want is to know whether if I call play, with the current configuration of the media element, it will succeed, without needing to call play. This is what if (video.canAutoplay()) {
video.play();
} else if (document.autoplayPolicy === 'allowed-muted') {
video.muted = true;
video.play();
} else {
// fall back to click-to-play
} |
@gkatsev it sounds like you're expecting that canAutoplay() would include whether or not a user activation is currently present? |
Yes, it would be a lot less useful to me if it didn't. |
IMMO I think the user activation is no something we need to discuss in the API level, that is more like an implementation detail. User agents can freely determine what actual mechanism they want to use for blocking autoplay. If they want to use the user acitvation, then the result returned by the autoplay policy detection API should be already considered the user activation and to simply tell web developers whether they can play media or not. User agent can also choose other implementations, such like only allowing autoplay on the media element that has been clicked by users. In addition, another benefit using So if the page only allows inaudible media, calling // Assume that `document.autoplayPolicy === 'allowed-muted'`
// canAutoplay version
let video = document.createElement("video");
video.src = "video_without_audio_track.webm";
await new Promise(r => v.onloadedmetadata = r);
if (video.canAutoplay) {
video.play();
} else {
// handle the case when autoplay is not allowed
// eg. showing the click-to-play icon
}
// autoplayPolicy version
let video = document.createElement("video");
video.src = "video_without_audio_track.webm";
if (video.autoplayPolicy == "allow-muted") {
video.play();
} else {
// handle the case when autoplay is not allowed
// eg. showing the click-to-play icon
} |
Yeah, I would agree with that. As long as if user activation is required, it's included in the decision for the response of canAutoplay.
That should be fine.
|
@alastor0325 It sounds like you're saying that If we do end up agreeing on
|
This sounds reasonable.
If web developers care about the consistent result before and after loading metadata, then
@dalecurtis Does the current scope mean the moment while
Agree. Just for the confirmation, does Thank you. |
Sounds reasonable to me ass well.
I was using scope to refer to the current call stack, I expect there's some more proper webism/specism for that.
Yes that's my read of the situation. I expect there's some risk that folks will unknowingly call it too early, so I wonder if returning false is actually okay and rather we should throw or return an enum value ("true", "false", "unknown"). |
What the difference would be for web developers when they receive "false" and "unknown"? If they will try to request the autoplay later on both situations, then it seems "unknown" would become useless. In addition, as the returned value of @gkatsev I wonder if adding the "unknown" will help web developers, or simple boolean is enough? Thank you. |
Yeah I couldn't really come up with any catastrophic failure modes if they call too early, but I did want to mention it in case anyone else here could think of something bad that might happen. |
Sure, thank for bring that to the table. So if no one has any other concern of returning @jernoble As you proposed the Thank you. |
I would say a boolean is fine. Though, I'm also slightly biased as I'm familiar with this work. A boolean is definitely simpler than an enum, especially if the enum looks like a boolean. We could put a note in the spec that recommends listening to I can ask the video-dev community for input if you think it would be valuable. |
The goal of the |
To clarify, are both |
That will be great, I'd like to know more about how web developers feel about current API proposal.
From my current understanding, yes. This issue is only aim to determine whether the API interface for HTMLMediaElement should be
So far |
Firstly this is great to see that we're going to be able to determine if auto play will work synchronously without waiting for I'm trying to understand if we really need both Wouldn't e.g if (document.autoplayPolicy === 'disallowed') {
// fallback to click-to-play
} else {
if (document.autoplayPolicy === 'allowed-muted') {
vid.muted = true;
}
vid.play();
}
|
|
Ah right. So autoPlayPolicy would be Should it change to |
Yeh I’d vote for this. I think if we have both canAutoplay() return true but the policy say ‘disallowed’ when asked in the same call stack it’s a bit strange. And if that’s the case, I think canAutoPlay() might be redundant? |
What about the following scenario: |
If user agents could change their decision based on the specific element/audio context I think they should be separate rather than trying to have a global one, so yeh have one on |
Looking at the old explainer (#8), the document level property can help you decide which source to use. The element level property can decide whether you can continue playback as is. |
👍 We could still have ‘autoplayPolicy’ on the element itself for this though? The element doesn’t have to be initialised with a 'src' does it? So you could create the element, decide what source to load, and then set the ‘src’? |
I think that is what For if (vid.autoplayPolicy === 'disallowed') {
// fallback to click-to-play and probably no need to load media resource
} else {
vid.src = "video.webm";
if (vid.autoplayPolicy === 'allowed-muted') {
vid.muted = true; // or video.src = "video_no_audio.webm"
}
vid.play();
} For // Determine the media resource
if (document.autoplayPolicy === 'disallowed') {
// fallback to click-to-play and probably no need to load media resource for vid
} else if (document.autoplayPolicy === 'allowed-muted') {
// either loading inaudible resource, or simply mute vid
}
await new Promise(r => v.onloadedmetadata = r);
if (vid.canAutoplay) {
await vid.play();
} But just looking the code above, I feel the |
Yeh so this is still possible if it was
I think the result is only more complicated when it's on |
Sorry for my late reply. So one example of mixing
Indeed, using The original idea of introducing document level API is about solving the resource selection issue. If @dalecurtis @eric-carlson @gkatsev May I get the opinion from y'all? Also, @padenot, WDYH about directly adding an attribute on AudioContext for autoplay detection? Thank you. |
|
It does: https://github.com/WebAudio/web-audio-api-v2/issues/83#issuecomment-846127059 |
The document API is sufficient: var ac = new AudioContext;
if (document.autoplayPolicy == "allowed") {
ac.onstatechange = function() {
if (ac.state == "running") {
// start the audio app
}
} else {
// display a bit of UI to ask the user to start the app
// audio starts via calling `ac.resume()` from a handler,
// `onstatechange` allows knowing when the audio stack
// is ready.
}
} I don't know of a reason to not do this, because the |
TIL. Thanks @padenot. I think that takes us back to having |
Given web audio and the media element work differently and are different api’s I’m not sure they need to share the same document property? In the future will there always be a value that satisfies both apis?
I still think this is a reason to have an It also means you only have one property to check for autoplay, not 2 (for the media element case) |
In the code above is anyone actually doing:
Instead of
Basically the only benefit of the element level check is to incorporate metadata, but is that needed? |
I don’t think that’s that’s the only purpose? An element api would take other context into consideration, like whether the click is from a user action if that’s required. A document api couldn’t do that. |
Why couldn't the document level API check the presence of a user-activation? Whether we want to do that is a different question. |
If user-activation is per element rather than per document, the document policy couldn't reliably tell us whether a given element will be allowed or not allowed to play. Personally, I find a document level attribute is useful in addition to a video element property. Using the document level property, we can check what the current state of the world is before deciding to go down a particular path, and it doesn't require us to create a potentially temporary video element to do this check (especially given the current limit on this in Chrome). Then, the video element property can tell us what this particular element can do. This is also why I favor I'm not terribly familiar with the WebAudio API, but it seems like it'll be useful to have a single place where developers can query to know whether playing back something with sound will work or not. |
Interesting. Does this throw when you create the element or at a later stage once hitting the limit? If it’s after construction then this limit could also be factored in to the returned policy? |
Looks like the limit has increased by quite a lot, but yes, it threw when the limit was hit. Previously it was 75, it'll be 1000 at some point soon. See https://bugs.chromium.org/p/chromium/issues/detail?id=1232649 |
Just tried tweaking the code for the demo in that ticket slightly and it looks like it's not So it is an example of something else that could be part of the logic behind code to reproducefor (let i = 0; i < 100; i++) {
const v = document.createElement('video');
v.muted = true;
v.srcObject = localVideo.srcObject;
Promise.race([v.play(), new Promise((resolve, reject) => setTimeout(() => reject('timeout'), 500))]).catch((e) => console.log(e))
} on https://webrtc.github.io/samples/src/content/peerconnection/pc1/ after clicking start gives 26 logs and 26 |
(I don't think that issue is relevant to this discussion, so we should probably avoid derailing -- that intervention affects loading prior to playback. FWIW: It was an intervention intended only to capture extremely rare cases of element leakage that crashed users systems, but the data used to set the limits was not normally distributed and unfortunately RTC ended up disproportionately affected) |
Based on the discussions so far, the only argument for Proposal 1 : Proposal 2 : |
sgtm, thanks @alastor0325! |
Lgtm too! By the way @alastor0325 I work for the BBC but my comments here were not on behalf of the BBC |
Thanks, @alastor0325. SGTM. Also, I speak on behalf of Brightcove as well as Video.js. I think the main downside of |
Hmm I see your point. Maybe we need to distinguish between:
? What we have now just helps figure out how to make the play call work at a given point. And after writing that I realise this is essentially what you had originally @gkatsev . Sorry for being so slow :| So IMO:
I think both would be needed though for it to be most useful. |
Hi, all, |
Hi @alastor0325,
It looks like it does actually cover my points there given you’re proposing a property on |
As the first version of PR has been merged, this issue could be closed. Because in the merged first version, we already chose to use |
Hi, I'm going to help on editing the spec of autoplay detection.
But I found that there are two proposed names for the API on HTMLMediaElement. One is
autoplayPolicy
from issue#11.Another one is the
canAutoplay
from the explainer, and this one returns a boolean.Should we decide a final naming and the form for this API before moving things forward? In addition, for the API naming on
Document
, does everyone agree with usingautoplayPolicy
like issue#11?Firefox has implemented an exprimental feature called
allowedToPlay
based on the previous discussion threads and it's easy for us to change that name to the one that we will decide to use for the final decision.The text was updated successfully, but these errors were encountered: