Movatterモバイル変換


[0]ホーム

URL:


project logoChromium Docs

Autoplay of HTMLMediaElements

Autoplay is the concept of playing media elements without user gesture. The policy that defines when autoplay is allowed is definedhere. The autoplay logic follows theHTML spec.

There are two ways of initiating autoplay:

  • Autoplay by attribute: Setting theautoplay attribute on the media element. The element will try to autoplay when thereadyState changes to HAVE_ENOUGH_DATA.
  • Autoplay byplay() method: Explicitly calling theplay() method without user gesture.

All the autoplay logic is handled by the AutoplayPolicy class. When the media element wants to perform some action (like unmute, autoplay by attribute orplay() method), it will send a request to AutoplayPolicy, and if the request is approved, the element can autoplay, otherwise it should be paused. Also the media element should inform the AutoplayPolicy about relevant changes such as “the element has been moved to a new document”.

User gesture lock

Each media element has a user gesture lock. If the element is allowed to autoplay, the lock is initialized asfalse, otherwise it'strue.

When the element is trying to initate autoplay, we check the gesture lock. If the lock isfalse, it will be allowed. Otherwise autoplay will be blocked. An exception is that if the element is a muted video element, the gesture lock check will be bypassed.

To unlock the gesture lock (make itfalse). The page needs to call play() or load() on the element when responding to a user gesture.

Autoplay flowchart

The treatments of autoplay by different methods are different. For autoplay by attribute, it is:

Autoplay by attribute

This means if autoplay is initiated by attribute, it enters the autoplaying phase, we play it as long as the video is visible. When the page explicitly callsplay(),pause(), we leave the autoplaying phase. When the page tries to unmute the video, we check the gesture lock and pause the video if it is stilltrue.

For autoplay byplay() method, it is:

Autoplay by play() method

This means if autoplay is initiated byplay() method, we continue playing the video as normalplay(). However if the page tries to unmute the video, we check the gesture lock and pause the video if it is stilltrue.


[8]ページ先頭

©2009-2025 Movatter.jp