The HTMLMediaElement interface adds to HTMLElement the properties and methods needed to support basic media-related functionality that's common to both audio and video. The HTMLVideoElement and HTMLAudioElement elements inherit this interface. special properties and methods (beyond the properties and methods available for all children of HTMLElement), that are common to all media-related objects.
Properties
Inherits properties from its parent, HTMLElement.
| Name | Type | Description | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
audioTracks |
AudioTrackList |
Represents the list of AudioTrack objects contained in the element. |
||||||||||||||||||
autoplay |
Boolean |
Reflects the autoplay HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption. |
||||||||||||||||||
buffered Read only |
TimeRanges |
The ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed. The returned TimeRanges object is normalized. |
||||||||||||||||||
controller |
MediaController |
Represents the media controller associated to the element, or null if none is linked to it. |
||||||||||||||||||
controls |
Boolean |
Reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed. |
||||||||||||||||||
crossOrigin |
DOMString |
The CORS setting for this image element. See CORS settings attributes for details. | ||||||||||||||||||
currentSrc Read only |
DOMString |
The absolute URL of the chosen media resource (if, for example, the server selects a media file based on the resolution of the user's display), or an empty string if the networkState is EMPTY. |
||||||||||||||||||
currentTime |
double |
The current playback time, in seconds. Setting this value seeks the media to the new time. | ||||||||||||||||||
defaultMuted |
Boolean |
Reflects the muted HTML attribute, indicating whether the media element's audio output should be muted by default. This property has no dynamic effect, to mute and unmute the audio output, use the muted property. |
||||||||||||||||||
defaultPlaybackRate |
double |
The default playback rate for the media. 1.0 is "normal speed," values lower than 1.0 make the media play slower than normal, higher values make it play faster. The value 0.0 is invalid and throws a NOT_SUPPORTED_ERR exception. |
||||||||||||||||||
duration Read only |
double |
The length of the media in seconds, or zero if no media data is available. If the media data is available but the length is unknown, this value is NaN. If the media is streamed and has no predefined length, the value is Inf. |
||||||||||||||||||
ended Read only |
Boolean |
Indicates whether the media element has ended playback. | ||||||||||||||||||
error Read only |
MediaError |
The MediaError object for the most recent error, or null if there has not been an error. |
||||||||||||||||||
initialTime Read only |
double |
The initial playback position in seconds. | ||||||||||||||||||
loop |
Boolean |
Reflects the loop HTML attribute, indicating whether the media element should start over when it reaches the end. |
||||||||||||||||||
mediaGroup |
DOMString |
Reflects the mediagroup HTML attribute, indicating the name of the group of elements it belongs to. A group of media elements shares a common controller. |
||||||||||||||||||
| mediaKeys Read only | MediaKeys |
Returns a reference to the MediaKeys interface, which is a set of keys that an associated HTMLMediaElement can use for decription of media data during playback. |
||||||||||||||||||
mozAudioChannelType |
DOMString |
Can be used to set the audio channel that the sound coming from an <audio> or <video> element will play in, on a Firefox OS device. See Using the AudioChannels API for more details. |
||||||||||||||||||
mozChannels Read only |
long |
The number of channels in the audio resource (e.g., 2 for stereo). |
||||||||||||||||||
mozFrameBufferLength |
long |
Indicates the number of samples that will be returned in the framebuffer of each The |
||||||||||||||||||
mozSampleRate Read only |
long |
The number of samples per second that will be played. For example, 44100 samples per second is the sample rate used by CD audio. | ||||||||||||||||||
mozSrcObject |
MediaStream |
Lets you set or get the Media Stream to be played or being played. | ||||||||||||||||||
muted |
Boolean |
true if the audio is muted, and false otherwise. |
||||||||||||||||||
networkState |
unsigned short |
The current state of fetching the media over the network.
|
||||||||||||||||||
paused Read only |
Boolean |
Indicates whether the media element is paused. | ||||||||||||||||||
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 Read only |
TimeRanges |
The ranges of the media source that the browser has played, if any. | ||||||||||||||||||
preload |
DOMString |
Reflects the preload HTML attribute, indicating what data should be preloaded, if any. Possible values are: none, metadata, auto. See preload attribute documentation for details. |
||||||||||||||||||
readyState Read only |
unsigned short |
The readiness state of the media.
|
||||||||||||||||||
seekable Read only |
TimeRanges |
The time ranges that the user is able to seek to, if any. | ||||||||||||||||||
seeking Read only |
Boolean |
Indicates whether the media is in the process of seeking to a new position. | ||||||||||||||||||
src |
DOMString |
Reflects the src HTML attribute, containing the URL of a media resource to use. Gecko implements a similar functionality for streams: mozSrcObject. |
||||||||||||||||||
textTracks |
TextTrackList |
Represents the list of TextTrack objects contained in the element. |
||||||||||||||||||
videoTracks |
VideoTrackList |
Represents the list of 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 |
The audio volume, from 0.0 (silent) to 1.0 (loudest). |
Methods
Inherits methods from its parent, HTMLElement.
| Name & Arguments | Return | Description |
|---|---|---|
canPlayType(in DOMString type) |
|
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() |
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) |
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 |
Pauses the media playback. |
play() |
void |
Begins playback of the media. |
| setMediaKeys | Promise |
Sets the MediaKeys keys to use when decrypting media during playback. |
Events
Audio and Video elements can fire quite a few different events.
Specifications
| Specification | Status | Comment |
|---|---|---|
| WHATWG HTML Living Standard The definition of 'HTMLMediaElement' in that specification. |
Living Standard | No change from HTML5 |
| HTML5 The definition of 'HTMLMediaElement' in that specification. |
Recommendation | Initial definition. |
| Unknown The definition of 'Encrypted Media Extensions' in that specification. |
Unknown | Adds MediaKeys, MediaEncryptedEvent, and setMediaKeys. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | 3.5 (1.9.1) [1] | 9 | ? | ? |
buffered property |
(Yes) | 4.0 (2.0) | 9 | ? | ? |
defaultMuted property |
(Yes) | 11.0 (11.0) | ? | ? | ? |
loop property |
(Yes) | 11.0 (11.0) | 9 | ? | ? |
seekable property |
(Yes) | 8.0 (8.0) | 9 | ? | ? |
defaultPlaybackRate property |
(Yes) | 20.0 (20.0) | 9 | ? | ? |
playbackRate property |
(Yes) | 20.0 (20.0) | 9 | ? | ? |
preservesPitch property |
(Yes)webkit | 20.0 (20.0)moz | Not supported | Not supported | Not supported |
preload property |
(Yes) | 4.0 (2.0) (implemented autobuffer previously) |
? | ? | ? |
played property |
(Yes) | 15.0 (15.0) | ? | ? | ? |
crossOrigin property |
(Yes) | 12.0 (12.0) as crossorigin12.0 (12.0) |
? | ? | ? |
mozAudioChannelType property |
Not supported | Not supported | Not supported | Not supported | Not supported |
mozChannels, mozFrameBufferLength, mozSampleRate properties |
Not supported | 4.0 (2.0) | Not supported | Not supported | Not supported |
mozGetMetadata() |
Not supported | 17.0 (17.0) | Not supported | Not supported | Not supported |
mozLoadFrom() Obsolete since Gecko 24 |
Not supported | 3.6 (1.9.2) | Not supported | Not supported | Not supported |
mozSrcObject property |
Not supported | 18.0 (18.0) | Not supported | Not supported | Not supported |
initialTime property |
? | 9.0 (9.0), removed in 23.0 (23.0) | ? | ? | ? |
fastSeek method |
? | Not supported bug 778077 | ? | ? | ? |
startDate property |
? | Not supported bug 847376 | ? | ? | ? |
mediaGroup and controller properties |
? | Not supported bug 847377 | ? | ? | ? |
audioTracks, and videoTracks properties |
? | 33.0 (33.0), behind the media.track.enabled preference. |
? | ? | ? |
textTracks property |
? | On Nightly, behind the media.webvtt.enabled preference. |
? | ? | ? |
| Feature | Android | Firefox Mobile (Gecko) | Firefox OS (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | ? | (Yes) | (Yes) |
buffered property |
(Yes) | 4.0 (2.0) | (Yes) | ? | ? | ? |
defaultMuted property |
(Yes) | 11.0 (11.0) | (Yes) | ? | ? | ? |
loop property |
(Yes) | 11.0 (11.0) | (Yes) | ? | ? | ? |
seekable property |
(Yes) | 8.0 (8.0) | (Yes) | ? | ? | ? |
defaultPlaybackRate property |
(Yes) | 20.0 (20.0) | (Yes) | ? | ? | ? |
playbackRate property |
(Yes) | 20.0 (20.0) | (Yes) | ? | ? | ? |
preservesPitch property |
(Yes)webkit | 20.0 (20.0)moz | (Yes) | Not supported | Not supported | Not supported |
preload property |
(Yes) | 4.0 (2.0) | (Yes) | ? | ? | ? |
played property |
(Yes) | 15.0 (15.0) | (Yes) | ? | ? | ? |
crossOrigin property |
(Yes) | 12.0 (12.0) as crossorigin22.0 (22.0) |
(Yes) | ? | ? | ? |
mozAudiochannelType |
Not supported | Not supported | 1.0.1 | Not supported | Not supported | Not supported |
mozChannels, mozFrameBufferLength, mozSampleRate properties |
Not supported | 4.0 (2.0) | (Yes) | Not supported | Not supported | Not supported |
mozGetMetadata() |
Not supported | 17.0 (17.0) | (Yes) | Not supported | Not supported | Not supported |
mozLoadFrom() |
Not supported | 1.0 (1.9.2) Removed from 24.0 (24) |
(Yes) | Not supported | Not supported | Not supported |
mozSrcObject property |
Not supported | 18.0 (18.0) | (Yes) | Not supported | Not supported | Not supported |
initialTime property |
? | 9.0 (9.0), removed in 23.0 (23.0) | (Yes) | ? | ? | ? |
fastSeek method |
? | Not supported bug 778077 | (Yes) | ? | ? | ? |
startDate property |
? | Not supported bug 847376 | (Yes) | ? | ? | ? |
mediaGroup and controller properties |
? | Not supported bug 847377 | (Yes) | ? | ? | ? |
audioTracks, and videoTracks properties |
? | 33.0 (33.0), behind the media.track.enabled preference. |
(Yes) | ? | ? | ? |
textTracks property |
? | On Nightly, behind the media.webvtt.enabled preference. |
(Yes) | ? | ? | ? |
[1] The NETWORK_LOADED state was removed to align with the HTML spec in Gecko 2.0 (Firefox 4).
See also
- References
<video>and<audio>HTML elements.HTMLVideoElementandHTMLAudioElementinterfaces, derived fromHTMLMediaElement.
- Articles