HTMLMediaElement.autoplay
property reflects the
autoplay
HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.
A media element whose source is a
MediaStream
and whose
autoplay
特性为
true
will begin playback when it becomes active (that is, when
MediaStream.active
becomes
true
).
注意: Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, autoplay can be useful when creating media elements whose source will be set at a later time, under user control.
For a much more in-depth look at autoplay, autoplay blocking, and how to respond whena autoplay is blocked by the user's browser, see our article Autoplay guide for media and Web Audio APIs .
HTMLMediaElement.autoplay = true | false; var autoplay = HTMLMediaElement.autoplay;
A
布尔
whose value is
true
if the media element will begin playback as soon as enough content has loaded to allow it to do so without interruption.
注意:
Some browsers offer users the ability to override
autoplay
in order to prevent disruptive audio or video from playing without permission or in the background. Do not rely on
autoplay
actually starting playback and instead use
play
事件。
...
<video id="video" controls> <source src="https://player.vimeo.com/external/250688977.sd.mp4?s=d14b1f1a971dde13c79d6e436b88a6a928dfe26b&profile_id=165"> </video>
*** Disable autoplay (recommended) ***
false is the default value
document.querySelector('#video').autoplay = false;
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'HTMLMediaElement.autoplay' in that specification. |
实时标准 | 无变化自 HTML5 |
|
HTML5
The definition of 'HTMLMediaElement.autoplay' in that specification. |
推荐 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
autoplay
|
Chrome 43 | Edge 12 | Firefox 3.5 | IE 9 | Opera 30 | Safari 6 | WebView Android 43 | Chrome Android 43 | Firefox Android Yes | Opera Android 30 | Safari iOS Yes | Samsung Internet Android 4.0 |
完整支持
HTMLMediaElement
.
<audio>
and
<video>
元素
HTMLMediaElement
BeforeUnloadEvent
DOMStringMap
ErrorEvent
GlobalEventHandlers
HTMLAnchorElement
HTMLAreaElement
HTMLAudioElement
HTMLBRElement
HTMLBaseElement
HTMLBaseFontElement
HTMLBodyElement
HTMLButtonElement
HTMLCanvasElement
HTMLContentElement
HTMLDListElement
HTMLDataElement
HTMLDataListElement
HTMLDialogElement
HTMLDivElement
HTMLDocument
HTMLElement
HTMLEmbedElement
HTMLFieldSetElement
HTMLFormControlsCollection
HTMLFormElement
HTMLFrameSetElement
HTMLHRElement
HTMLHeadElement
HTMLHeadingElement
HTMLHtmlElement
HTMLIFrameElement
HTMLImageElement
HTMLInputElement
HTMLIsIndexElement
HTMLKeygenElement
HTMLLIElement
HTMLLabelElement
HTMLLegendElement
HTMLLinkElement
HTMLMapElement
HTMLMetaElement
HTMLMeterElement
HTMLModElement
HTMLOListElement
HTMLObjectElement
HTMLOptGroupElement
HTMLOptionElement
HTMLOptionsCollection
HTMLOutputElement
HTMLParagraphElement
HTMLParamElement
HTMLPictureElement
HTMLPreElement
HTMLProgressElement
HTMLQuoteElement
HTMLScriptElement
HTMLSelectElement
HTMLShadowElement
HTMLSourceElement
HTMLSpanElement
HTMLStyleElement
HTMLTableCaptionElement
HTMLTableCellElement
HTMLTableColElement
HTMLTableDataCellElement
HTMLTableElement
HTMLTableHeaderCellElement
HTMLTableRowElement
HTMLTableSectionElement
HTMLTemplateElement
HTMLTextAreaElement
HTMLTimeElement
HTMLTitleElement
HTMLTrackElement
HTMLUListElement
HTMLUnknownElement
HTMLVideoElement
HashChangeEvent
历史
ImageData
定位
MessageChannel
MessageEvent
MessagePort
Navigator
NavigatorGeolocation
NavigatorID
NavigatorLanguage
NavigatorOnLine
NavigatorPlugins
PageTransitionEvent
Plugin
PluginArray
PopStateEvent
PortCollection
PromiseRejectionEvent
RadioNodeList
Transferable
ValidityState
Window
WindowBase64
WindowEventHandlers
WindowTimers