--- title: HTMLMediaElement slug: Web/API/HTMLMediaElement tags: - API - HTML - HTMLMediaElement - HTML媒体元素 - Media - Video translation_of: Web/API/HTMLMediaElement ---
从父级 {{domxref("HTMLElement")}}, {{domxref("Element")}}, {{domxref("Node")}}, 和 {{domxref("EventTarget")}} 继承属性
名称 | 类型 | 描述 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
audioTracks |
{{domxref("AudioTrackList")}} |
表示在该元素中包含的{{domxref("AudioTrack")}}对象列表 |
||||||||||||||||||
autoplay |
{{domxref("Boolean")}} |
表示{{ htmlattrxref("autoplay", "video") }}的HTML属性,表明在视频加载可用时是否不中断地自动播放资源 |
||||||||||||||||||
buffered {{readonlyinline}} |
{{ domxref("TimeRanges") }} | buffered 属性会告诉浏览器哪一部分的媒体已经被下载(如果浏览器支持的话),按照标准会返回一个{{ domxref("TimeRanges") }}对象 |
||||||||||||||||||
controller |
{{ domxref("MediaController")}} |
返回当前媒体控制器的MediaController 对象,如果没有连接就返回null |
||||||||||||||||||
controls |
{{domxref("Boolean")}} | 映射在HTML标签。{{ htmlattrxref("controls", "video") }}属性控制是否显示用户播放界面的控制 HTML | ||||||||||||||||||
crossOrigin |
{{ domxref("DOMString") }} | 一个表示媒体元素 CORS 设置的{{ domxref("DOMString") }}。从 CORS settings attributes 查看更多详情 | ||||||||||||||||||
currentSrc {{readonlyinline}} |
{{ domxref("DOMString") }} | 用{{domxref("DOMString")}}表示媒体文件的绝对URL。如果networkState 为EMPTY, 那么值为空字符串。 |
||||||||||||||||||
currentTime |
double |
当前播放时间,单位为秒。为其赋值将会使媒体跳到一个新的时间。 | ||||||||||||||||||
defaultMuted |
{{domxref("Boolean")}} | 映射在HTML标签上。 {{ htmlattrxref("muted", "video") }} 属性表示媒体声音被播放时是否应该被静音。这个属性不能动态设置静音/不静音,如果希望设置静音/不静音,请使用 muted 属性 |
||||||||||||||||||
defaultPlaybackRate |
double |
控制媒体的播放速度。1.0表示正常的播放速度,如果值小于1.0,则播放速度会比”正常速度“慢,如果值大于1.0,则播放速度会比”正常速度“快。0.0是一个无效的值,并且会抛出 NOT_SUPPORTED_ERR 错误。 |
||||||||||||||||||
duration {{readonlyinline}} |
double |
媒体以秒为单位的总长度时间,如果媒体不可用,则为0. 如果媒体可用,但时间长度未知, 值为NAN. 如果媒体是以stream形式传输并且没有预定长度,则值为Inf。 | ||||||||||||||||||
ended {{readonlyinline}} |
{{domxref("Boolean")}} | 表示媒体是否已经播放完毕。 | ||||||||||||||||||
error {{readonlyinline}} |
{{ domxref("MediaError") }} | {{domxref("MediaError")}} 对象表示最近的错误,如果没有错误则值为 null 。 |
||||||||||||||||||
initialTime {{readonlyinline}} {{ non-standard_inline() }} {{deprecated_inline}} |
double |
初始播放位置(以秒为单位)。 | ||||||||||||||||||
loop |
{{domxref("Boolean")}} | 会映射在HTML标签 {{ htmlattrxref("loop", "video") }} 属性 , 决定该媒体是否循环播放. | ||||||||||||||||||
mediaGroup |
{{domxref("DOMString")}} | 反映在HTML {{ htmlattrxref("mediagroup", "video")}} 标签上。 表示元素所归属的分组,同一组的媒体元素会共享同一个控制器(controller )。 |
||||||||||||||||||
mediaKeys {{experimental_inline}}{{readonlyinline}} | {{domxref("MediaKeys")}} | Returns a reference to the {{domxref("MediaKeys")}} interface, which is a set of keys that an associated HTMLMediaElement can use for decription of media data during playback. | ||||||||||||||||||
mozAudioChannelType {{ non-standard_inline() }} |
{{domxref("DOMString")}} | Can be used to set the audio channel that the sound coming from an {{htmlelement("audio")}} or {{htmlelement("video")}} element will play in, on a Firefox OS device. See Using the AudioChannels API for more details. | ||||||||||||||||||
mozChannels {{readonlyinline}} {{ non-standard_inline() }} |
long |
声道数 (比如 2 是立体声). |
||||||||||||||||||
mozFrameBufferLength {{ non-standard_inline() }} |
long |
Indicates the number of samples that will be returned in the framebuffer of each The |
||||||||||||||||||
mozSampleRate {{readonlyinline}} {{ non-standard_inline() }} |
long |
播放内容的采样率(每秒采样次数)。比如,44100 就是一张CD的采样率。 | ||||||||||||||||||
mozSrcObject {{ non-standard_inline() }} |
{{domxref("MediaStream")}} | Lets you set or get the Media Stream to be played or being played. | ||||||||||||||||||
muted |
{{domxref("Boolean")}} | 静音时为true ,否则是false . |
||||||||||||||||||
networkState |
unsigned short |
获取媒体时的网络状态
|
||||||||||||||||||
paused {{readonlyinline}} |
{{domxref("Boolean")}} | 指示媒体元素是否被暂停。 | ||||||||||||||||||
playbackRate |
double |
The current rate at which the media is being played back. This is used to implement user controls for fast forward, slow motion, and so forth. The normal playback rate is multiplied by this value to obtain the current rate, so a value of 1.0 indicates normal speed. If the The pitch of the audio is corrected by default and is the same for every speed. Some browsers implement the non-standard |
||||||||||||||||||
played {{readonlyinline}} |
{{ domxref("TimeRanges") }} | 媒体可被播放的范围。 | ||||||||||||||||||
preload |
{{ domxref("DOMString") }} | Reflects the {{ htmlattrxref("preload", "video") }} HTML attribute, indicating what data should be preloaded, if any. Possible values are: none , metadata , auto . See {{ htmlattrxref("preload", "video") }} attribute documentation for details. |
||||||||||||||||||
readyState {{readonlyinline}} |
unsigned short |
The readiness state of the media.
|
||||||||||||||||||
seekable {{readonlyinline}} |
{{ domxref("TimeRanges") }} | The time ranges that the user is able to seek to, if any. | ||||||||||||||||||
seeking {{readonlyinline}} |
{{domxref("Boolean")}} | Indicates whether the media is in the process of seeking to a new position. | ||||||||||||||||||
sinkId {{readonlyinline}}{{experimental_inline}} |
{{domxref("DOMString")}} | The unique ID of the audio device delivering output, or an empty string if it is using the user agent default. This ID should be one of the MediaDeviceInfo.deviceid values returned from {{domxref("MediaDevices.enumeratedDevices()")}}, id-multimedia , or id-communications . |
||||||||||||||||||
src |
{{ domxref("DOMString") }} | Reflects the {{ htmlattrxref("src", "video") }} HTML attribute, containing the URL of a media resource to use. Gecko implements a similar functionality for streams: mozSrcObject . |
||||||||||||||||||
textTracks |
{{domxref("TextTrackList")}} | Represents the list of {{domxref("TextTrack")}} objects contained in the element. | ||||||||||||||||||
videoTracks |
{{domxref("VideoTrackList")}} | Represents the list of {{domxref("VideoTrack")}} objects contained in the element.
Note: Yet Gecko supports only single track playback, and the parsing of tracks' metadata is only available for media with Ogg container foramt. |
||||||||||||||||||
volume |
double |
表示音频的音量。值从0.0(静音)到1.0(最大音量)。 |
Inherits methods from its parent, {{domxref("HTMLElement")}}.
Name & Arguments | Return | Description |
---|---|---|
canPlayType(in {{ domxref("DOMString") }} type) |
{{ domxref("DOMString") }}
|
Determines whether the specified media type can be played back.
Note: Previously |
fastSeek(double time) |
void |
Directly seek to the given time. |
load() |
void |
Reset the media element and restart selecting the media resource. Any pending events are discarded. How much media data is fetched is still affected by the preload attribute. This method can be useful for releasing resources after any src attribute and source element descendants have been removed. Otherwise, it is usually unnecessary to use this method, unless required to rescan source element children after dynamic changes. |
mozGetMetadata() {{ non-standard_inline() }} |
Object |
The mozGetMetadata method returns a javascript object whose properties represent metadata from the playing media resource as {key: value} pairs. A separate copy of the data is returned each time the method is called.This method must be called after the loadedmetadata event fires. |
mozLoadFrom(HTMLMediaElement other) {{ non-standard_inline() }} {{ deprecated_inline() }} |
void |
This method, available only in old Mozilla's implementation, loads data from another media element. This works similarly to load() except that instead of running the normal resource selection algorithm, the source is simply set to the other element's currentSrc .This is optimized so this element gets access to all of the other element's cached and buffered data; in fact, the two elements share downloaded data so that data downloaded by either element is available to both. |
pause() |
void |
暂停播放。 |
play() |
void |
开始播放。 |
setMediaKeys {{experimental_inline}} | {{jsxref("Promise")}} | Sets the {{domxref("MediaKeys")}} keys to use when decrypting media during playback. |
setSinkId {{experimental_inline}} | {{jsxref("Promise")}} | Sets the ID of the audio device through which audio output should be rendered if the application is authorized to play out of a given device. |
Audio and Video elements can fire quite a few different events.
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "the-video-element.html#htmlmediaelement", "HTMLMediaElement")}} | {{Spec2('HTML WHATWG')}} | No change from {{SpecName('HTML5 W3C')}} |
{{SpecName('HTML5 W3C', "embedded-content-0.html#htmlmediaelement", "HTMLMediaElement")}} | {{Spec2('HTML5 W3C')}} | Initial definition. |
{{SpecName('Encrypted Media Extensions', '#introduction', 'Encrypted Media Extensions')}} | {{Spec2('Encrypted Media Extensions')}} | Adds {{domxref("MediaKeys")}}, {{domxref("MediaEncryptedEvent")}}, and setMediaKeys. |
{{Compat("api.HTMLMediaElement")}}
HTMLMediaElement
.