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

[TPAC 2018] Autoplay Policy Informal Meeting Notes #1

Closed
beaufortfrancois opened this issue Oct 25, 2018 · 11 comments
Closed

[TPAC 2018] Autoplay Policy Informal Meeting Notes #1

beaufortfrancois opened this issue Oct 25, 2018 · 11 comments

Comments

@beaufortfrancois
Copy link

beaufortfrancois commented Oct 25, 2018

For posterity, here are the notes of the Autoplay Policy Informal Meeting at TPAC 2018, October 23rd.

Attendees

  • Jer Noble, Apple
  • Scott Low, Microsoft
  • Paul Adenot, Mozilla
  • Francois Beaufort, Google
  • Mounir Lamouri, Google

The outcome of this discussion is that we’d like an autoplay policy on document and a method on a HTMLMediaElement to know if autoplay will succeed.

It was discussed using the upcoming User Activation API (instead of the canAutoplay method) but since Apple folks are not sure to actually implement it, it was decided to not rely on this.

Disclaimer: names are subject to change

document.autoplayPolicy returns a enum string that can change overtime based on user session activity:

  • “allowed” if autoplay is currently allowed.
  • “allowed-muted” if muted video autoplay is currently allowed.
  • “disallowed” is autoplay is not current allowed.
  • MAYBE: “prompt” if autoplay will trigger a prompt (iif firefox decides to go that road)

HTMLMediaElement.canAutoplay() returns a promise that resolves if autoplay for a specific media element is allowed or rejects with some helpful error if not:

video.canAutoplay()
.then(_ => {
  // When muted videos can autoplay, it could be either
  // because the video is muted, or the video has no audio track.
  // It would also succeed if the call is during a user activation,
  // or if the video was previously played.
  // The video must have metadata loaded (readyState > HAVE_NOTHING).
})
.catch(error => {
  // If the video metadata did not load (readyState == HAVE_NOTHING),
  // or the call did not happen on a user gesture, or, when muted videos
  // are allowed if the video is not muted and has an audio track.
  // InvalidStateError will be used if the metadata did not load.
  // NotAllowedError will be used for all other cases.
});

Web Audio

Using the API for Web Audio would be as simple as:

const audioContext = new AudioContext();

if (audioContext.state === 'suspended') {
  if (document.autoplayPolicy === 'allowed') {
    // State is suspended only because hardware is slow.
  }
  if (document.autoplayPolicy === 'disallowed' ||
      document.autoplayPolicy === 'allowed-muted') {
    // State is suspended because of the autoplay policy.
    // TODO: Call audioContext.resume() after user gesture.
  }
}

Mozilla suggested to implement a new state called blocked, similar to the interrupted state implemented by Safari iOS. This state was meant to distinguish between suspended state caused by slow hardware and autoplay blocking. There was agreement that the document-level API was solving this use case (see above).

Autoplay Specification

In addition to drafting these changes, the discussions led to the creation of the wicg/autoplay repository in which a specification defining autoplay will be worked on. Paul Adenot was volunteered to author the specification :)

@mounirlamouri
Copy link
Member

mounirlamouri commented Nov 20, 2018

Because it's not mentioned above, I believe that document.autoplaPolicy should look like this:

partial interface Document {
  readonly attribute Promise<AutoplayPolicy> autoplayPolicy;
};

@jernoble
Copy link

Is there any precedent for a readonly attribute Promise? It seems really weird to have a resolved Promise for a value that can change over time.

@mounirlamouri
Copy link
Member

mounirlamouri commented Nov 21, 2018 via email

@cpearce
Copy link

cpearce commented Nov 21, 2018

Is there any precedent for a readonly attribute Promise? It seems really weird to have a resolved Promise for a value that can change over time.

Will spin this off into issue 6.

tidoust added a commit to tidoust/media-web-roadmap that referenced this issue Dec 17, 2018
Added to exploratory work. No real spec or implementation status, the proposal
is only described in an issue for now:
w3c/autoplay#1

Fix w3c#350.
xfq pushed a commit to w3c/web-roadmaps that referenced this issue Dec 19, 2018
Added to exploratory work. No real spec or implementation status, the proposal
is only described in an issue for now:
w3c/autoplay#1

Fix #350.
@tadas-subonis
Copy link

Can this have also an explicit permission request like notifications?

    if (Notification.permission === "granted") {
      console.log("We have notification permission");
      return;
    }
    Notification.requestPermission();

At the moment, the way autoplay blocking is implemented is breaking VoIP applications that are waiting for somebody to call and only then ring the sounds (w/o user interaction).

@mounirlamouri
Copy link
Member

mounirlamouri commented Feb 8, 2019 via email

@tadas-subonis
Copy link

What I meant is that it doesn't have to be accessible ONLY through permissions.

At the moment, there are multiple mechanisms that disable the behaviour: https://sites.google.com/a/chromium.org/dev/audio-video/autoplay

Adding additional exception, when "audioapi" permission is granted would work perfectly. This way chat/voip developers will be able to request relevant permissions upon the start of the application, and it won't change the flow for the others.

@cpearce
Copy link

cpearce commented Feb 9, 2019

I think the WebRTC use case is separate and distinct from the annoying cases that browsers are mostly trying to block, and is probably only blocked because it passes through the same top level API surface; HTMLMediaElement.play().

Firefox allows sites which have been granted persistent camera and microphone permissions to autoplay, in order to permit cases like you're describing. Our opinion was that since the browser explicitly prompts the user for permission for the site to access the camera/microphone before a WebRTC stream plays, the user has clearly signaled intent to allow media on that site. Maybe you should file bugs with the other browsers asking them to implement the same exception?

@mounirlamouri
Copy link
Member

Chrome and Safari both allow autoplay while a page is using getUserMedia. It seemed a bit better than only relying on the permission.

@a2sheppy
Copy link

Would appreciate a heads-up when a specification is available for this, as this falls into my bailiwick docs-wise.

@alastor0325
Copy link
Collaborator

Close this issue because this is just for some old discussion, and we already started editing a specification for Autoplay Detection API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants
@cpearce @tadas-subonis @mounirlamouri @beaufortfrancois @jernoble @a2sheppy @alastor0325 and others