nsIDOMHTMLMediaElement

Table of contents

  1. 1. Method overview
  2. 2. Attributes
  3. 3. Methods
    1. 3.1. canPlayType()
    2. 3.2. load()
    3. 3.3. mozLoadFrom()
    4. 3.4. pause()
    5. 3.5. play()
  4. 4. See also

The basis for the nsIDOMHTMLAudioElement and nsIDOMHTMLVideoElement interfaces, which in turn implement the <audio> and <video> HTML5 elements.
1.0
7.0
Introduced
Gecko 1.9.1
Inherits from: nsIDOMHTMLElement Last changed in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

Method overview

DOMString canPlayType(in DOMString type);
void load();
void mozLoadFrom(in nsIDOMHTMLMediaElement other); Requires Gecko 1.9.2 Non-standard
void pause();
void play();

Attributes

Attribute Type Description
autobuffer Obsolete since Gecko 2.0 boolean true if the media should automatically begin to download, regardless of whether or not autoplay is true. Replaced with the preload attribute in Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) .
autoplay boolean true if playback should automatically begin as soon as enough media is available to do so without interruption.
buffered Requires Gecko 2.0 TimeRanges A static, normalized nsIDOMHTMLTimeRanges object describing the time ranges of the media that have been buffered.  Read only.
bufferedBytes ByteRanges A static, normalized ByteRanges object describing the byte ranges of the media that have been buffered.  Read only.  Unimplemented
bufferingRate float The average number of bits per second for the current download over the past few seconds.  If there is no download in progress, this value is 0.0.  Read only.  Unimplemented
bufferingThrottled boolean true if Firefox is intentionally throttling the bandwidth used by the download (such as when the download is paused), otherwise false. Read only.  Unimplemented
controls boolean true if user interface for controlling the media should be presented.
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 float The current playback time, in seconds.  Setting this value will seek the media to the new time.
defaultPlaybackRate float The default playback rate for the media.  The Ogg backend does not support this.  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 float 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 true if playback has finished.  Read only.
error nsIDOMHTMLMediaError The media's error status.  Read only.
mozFrameBufferLength Requires Gecko 2.0 Non-standard unsigned long The size, in bytes, of the frame buffer used by the audio stream. The default size for a media element with audio is mozChannels * 1024. The size must be between 512 and 16,384 bytes.
mozSampleRate Requires Gecko 2.0 Non-standard unsigned long The audio sample rate. Read only.
mozChannels Requires Gecko 2.0 Non-standard unsigned long The number of channels of audio. Read only.
muted boolean true if the audio is muted, otherwise false.
networkState unsigned short

The current state of the fetch of the media. Read only.

Constant Value Description
EMPTY 0 There is no data yet.  The readyState will also be HAVE_NOTHING.
LOADING 1 The media is loading.
LOADED_METADATA 2 The media's metadata has been loaded.
LOADED_FIRST_FRAME 3 The media's first frame has been loaded.
LOADED 4 The media has been fully loaded.
paused boolean true if the media playback is currently paused.  Read only.
playbackRate float 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.  Not supported by the Ogg backend.
preload DOMString

A string indicating what if any data should be preloaded at page load time.

Constant Value
"none" No data should be preloaded.
"metadata" Only metadata should be preloaded.
"auto" The browser should preload whatever it thinks is reasonable, up to and including the entire media resource.

An empty string is equivalent to the default, which is "auto". This value is a hint to the browser; it may be ignored or overridden. For example, specifying the autoplay attribute will typically cause this to be ignored, since the content obviously needs to be buffered before playback begins.

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

readyState unsigned short

The media's current readiness state.  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.
seeking boolean true if the media is in the process of seeking to a new position, otherwise false. Read only.
src DOMString The URL of the media to present.
totalBytes unsigned long The length, in bytes, of the media resource.  If the length is unknown, or the content is streamed and therefore has no specified length, this value is 0.  Read only.
volume float The current audio volume, from 0.0 (silent) to 1.0 (maximum).

Methods

canPlayType()

Determines whether or not the specified media type can be played back.

DOMString canPlayType(
  in DOMString type
);
Parameters
type
The media type to test for, such as "video/ogg".
Return value
  • "" if the specified type definitely cannot be played (since Gecko 1.9.1.2/ Firefox 3.5.2; was "no" in previous versions).
  • "probably" if the specified type appears to be playable.
  • "maybe" if it's impossible to be sure if the type can be played without actually attempting to do so.

Because media formats are complicated, and it's impossible to judge every possible detail from the type string, there is no such thing as 100% certain that the specified type can be played; the best you can do is "probably".

load()

Begins loading the media content from the server.

 void load();
Parameters

None.

Requires Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

mozLoadFrom()

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.

void mozLoadFrom(
  nsIDOMHTMLMediaElement other
); 
Parameters
other
An nsIDOMHTMLMediaElement object representing the element from which to load.

pause()

Pauses the media playback.

 void pause();
Parameters

None.

play()

Begins playback of the media. If you have changed the "src" attribute of the video tag since the page was loaded, you must call load() before play(), otherwise the original video will play again.

 void play();
Parameters

None.

Tags (10)

Attachments (0)

 

Attach file