HTMLMediaElement

« Gecko DOM Reference

HTML media elements (such as <audio> and <video> ) have special properties and methods (beyond the properties and methods available for all Elements). These media-specific properties and methods technically belong to three interfaces and are documented on the following three pages:

  • HTMLMediaElement interface (this page) - properties and methods common to both <audio> and <video>.
  • HTMLAudioElement - additional properties and methods available on the <audio> elements.
  • HTMLVideoElement - additional properties and methods available on the <video> elements.

Properties

Name Type Description
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 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. Read only.
controls Boolean Reflects the controls HTML attribute, indicating whether user interface items for controlling the resource should be displayed.
currentSrc 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. Read only.
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. Unimplemented (see bug 495040 )
duration 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. Read only.
ended Boolean Indicates whether the media element has ended playback. Read only.
error MediaError The {domxref("MediaError")}} object for the most recent error, or null if there has not been an error. Read only.
initialTime double The initial playback position in seconds. Read only.
loop Boolean Reflects the loop HTML attribute, indicating whether the media element should start over when it reaches the end.
mozChannels long The number of channels in the audio resource (e.g., 2 for stereo). Read only. Non-standard Requires Gecko 2.0
mozFrameBufferLength long

Indicates the number of samples that will be returned in the framebuffer of each MozAudioAvailable event. This number is a total for all channels, and by default is set to be the number of channels * 1024 (e.g., 2 channels * 1024 samples = 2048 total).

The mozFrameBufferLength property can be set to a new value, for lower latency, or larger amounts of data, etc. The size given must be a number between 512 and 16384. Using any other size results in an exception being thrown. The best time to set a new length is after the loadedmetadata event fires, when the audio info is known, but before the audio has started or MozAudioAvailable events have begun firing.Non-standard Requires Gecko 2.0

mozSampleRate long The number of samples per second that will be played, for example 44100. Read only. Non-standard Requires Gecko 2.0
muted Boolean true if the audio is muted, and false otherwise.
networkState unsigned short

The current state of fetching the media over the network.

Constant Value Description
NETWORK_EMPTY 0 There is no data yet.  The readyState is also HAVE_NOTHING.
NETWORK_IDLE 1  
NETWORK_LOADING 2 The media is loading.
NETWORK_NO_SOURCE [NETWORK_LOADED] 3  
paused Boolean Indicates whether the media element is paused. Read only.
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. Unimplemented (see bug 495040 )
played TimeRanges The ranges of the media source that the browser has played, if any. Read only.
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.

Replaced the autobuffer property in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) .

readyState unsigned short

The readiness state of the media. Read only.

Constant Value Description
HAVE_NOTHING 0 No information is available about the media resource.
HAVE_METADATA 1 Enough of the media resource has been retrieved that the metadata attributes are initialized.  Seeking will no longer raise an exception.
HAVE_CURRENT_DATA 2 Data is available for the current playback position, but not enough to actually play more than one frame.
HAVE_FUTURE_DATA 3 Data for the current playback position as well as for at least a little bit of time into the future is available (in other words, at least two frames of video, for example).
HAVE_ENOUGH_DATA 4 Enough data is available—and the download rate is high enough—that the media can be played through to the end without interruption.
seekable TimeRanges The time ranges that the user is able to seek to, if any. Read only.
seeking Boolean Indicates whether the media is in the process of seeking to a new position. Read only.
src DOMString Reflects the src HTML attribute, containing the URL of a media resource to use.
startOffsetTime Date Unimplemented (see bug 498253 )
volume double The audio volume, from 0.0 (silent) to 1.0 (loudest).

Methods

Name & Arguments Return Description
canPlayType(in DOMString type)

DOMString

  • probably: if the specified type appears to be playable.
  • maybe: if it's impossible to tell whether the type is playable without playing it.
  • The empty string: if the specified type definitely cannot be played.
Determines whether the specified media type can be played back.
load()
void Begins loading the media content from the server.
mozLoadFrom(HTMLMediaElement other) void

This method, available only in 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.

Non-standard Requires Gecko 1.9.2

pause() void Pauses the media playback.
play() void Begins playback of the media. If you have changed the src attribute of the media element since the page was loaded, you must call load() before play(), otherwise the original media plays again.

Browser compatibility

^ NETWORK_LOADED was removed to align with the HTML spec in Gecko 2.0.

  • Desktop
  • Mobile

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support ? 3.5 (1.9.1) 9 ? ?`
buffered property ? 4.0 (2.0) 9 ? ?
defaultMuted property ? 11.0 (11.0) ? ? ?
loop property ? 11.0 (11.0) 9 ? ?
seekable property ? 8.0 (8.0) 9 ? ?
playbackRate property ? -- 9 ? ?
preload property ? 4.0 (2.0) ? ? ?
played property ? 15.0 (15.0) ? ? ?
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support ? ? ? ? ?
buffered property ? 4.0 (2.0) ? ? ?
defaultMuted property ? 11.0 (11.0) ? ? ?
loop property ? 11.0 (11.0) ? ? ?
seekable property ? 8.0 (8.0) ? ? ?
playbackRate property ? -- ? ? ?
preload property ? 4.0 (2.0) ? ? ?
played property ? 15.0 (15.0) ? ? ?

Specification

HTML: Media elements

Tags (3)

Edit tags

Attachments (0)

 

Attach file