video elementaudio elementsource elementtrack elementvideo elementISSUE-9 (video-accessibility) blocks progress to Last Call
controls attribute: Interactive content.src attribute:
zero or more track elements, then
transparent, but with no media element descendants.src attribute: one or more source elements, then
zero or more track elements, then
transparent, but with no media element descendants.srcposterpreloadautoplayloopaudiocontrolswidthheightinterface HTMLVideoElement : HTMLMediaElement {
attribute unsigned long width;
attribute unsigned long height;
readonly attribute unsigned long videoWidth;
readonly attribute unsigned long videoHeight;
attribute DOMString poster;
attribute boolean audio;
};
A video element is used for playing videos or
movies.
Content may be provided inside the video
element; it is intended for older Web browsers which do
not support video, so that legacy video plugins can be
tried, or to show text to the users of these older browsers informing
them of how to access the video contents.
In particular, this content is not intended to address accessibility concerns. To make video content accessible to the blind, deaf, and those with other physical or cognitive disabilities, authors are expected to provide alternative media streams and/or to embed accessibility aids (such as caption or subtitle tracks, audio description tracks, or sign-language overlays) into their media streams.
The video element is a media element
whose media data is ostensibly video data, possibly
with associated audio data.
The src, preload, autoplay, loop, and controls attributes are the attributes common to all media
elements. The audio
attribute controls the audio
channel.
The poster
attribute gives the address of an image file that the user agent can
show while no video data is available. The attribute, if present,
must contain a valid non-empty URL potentially surrounded by
spaces.
The image given by the poster attribute, the poster
frame, is intended to be a representative frame of the video
(typically one of the first non-blank frames) that gives the user an
idea of what the video is like.
videoWidthvideoHeightThese attributes return the intrinsic dimensions of the video, or zero if the dimensions are not known.
The video element supports dimension
attributes.
This example shows how to detect when a video has failed to play correctly:
<script>
function failed(e) {
// video playback failed - show a message saying why
switch (e.target.error.code) {
case e.target.error.MEDIA_ERR_ABORTED:
alert('You aborted the video playback.');
break;
case e.target.error.MEDIA_ERR_NETWORK:
alert('A network error caused the video download to fail part-way.');
break;
case e.target.error.MEDIA_ERR_DECODE:
alert('The video playback was aborted due to a corruption problem or because the video used features your browser did not support.');
break;
case e.target.error.MEDIA_ERR_SRC_NOT_SUPPORTED:
alert('The video could not be loaded, either because the server or network failed or because the format is not supported.');
break;
default:
alert('An unknown error occurred.');
break;
}
}
</script>
<p><video src="tgif.vid" autoplay controls onerror="failed(event)"></video></p>
<p><a href="tgif.vid">Download the video file</a>.</p>
audio elementcontrols attribute: Interactive content.src attribute:
zero or more track elements, then
transparent, but with no media element descendants.src attribute: one or more source elements, then
zero or more track elements, then
transparent, but with no media element descendants.srcpreloadautoplayloopcontrols[NamedConstructor=Audio(),
NamedConstructor=Audio(in DOMString src)]
interface HTMLAudioElement : HTMLMediaElement {};
An audio element represents a sound or
audio stream.
Content may be provided inside the audio
element; it is intended for older Web browsers which do
not support audio, so that legacy audio plugins can be
tried, or to show text to the users of these older browsers informing
them of how to access the audio contents.
In particular, this content is not intended to address accessibility concerns. To make audio content accessible to the deaf or to those with other physical or cognitive disabilities, authors are expected to provide alternative media streams and/or to embed accessibility aids (such as transcriptions) into their media streams.
The audio element is a media element
whose media data is ostensibly audio data.
The src, preload, autoplay, loop, and controls attributes are the attributes common to all media
elements.
Audio( [ url ] )Returns a new audio element, with the src attribute set to the value
passed in the argument, if applicable.
source elementtrack elements.srctypemediainterface HTMLSourceElement : HTMLElement {
attribute DOMString src;
attribute DOMString type;
attribute DOMString media;
};
The source element allows authors to specify
multiple alternative media
resources for media
elements. It does not represent anything on its own.
The src attribute
gives the address of the media resource. The value must
be a valid non-empty URL potentially surrounded by
spaces. This attribute must be present.
Dynamically modifying a source element
and its attribute when the element is already inserted in a
video or audio element will have no
effect. To change what is playing, either just use the src attribute on the media
element directly, or call the load() method on the media
element after manipulating the source
elements.
The type
attribute gives the type of the media resource, to help
the user agent determine if it can play this media
resource before fetching it. If specified, its value must be
a valid MIME type. The codecs
parameter, which certain MIME types define, might be necessary to
specify exactly how the resource is encoded. [RFC4281]
The following list shows some examples of how to use the codecs= MIME parameter in the type attribute.
<source src='video.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src='video.mp4' type='video/mp4; codecs="avc1.58A01E, mp4a.40.2"'>
<source src='video.mp4' type='video/mp4; codecs="avc1.4D401E, mp4a.40.2"'>
<source src='video.mp4' type='video/mp4; codecs="avc1.64001E, mp4a.40.2"'>
<source src='video.mp4' type='video/mp4; codecs="mp4v.20.8, mp4a.40.2"'>
<source src='video.mp4' type='video/mp4; codecs="mp4v.20.240, mp4a.40.2"'>
<source src='video.3gp' type='video/3gpp; codecs="mp4v.20.8, samr"'>
<source src='video.ogv' type='video/ogg; codecs="theora, vorbis"'>
<source src='video.ogv' type='video/ogg; codecs="theora, speex"'>
<source src='audio.ogg' type='audio/ogg; codecs=vorbis'>
<source src='audio.spx' type='audio/ogg; codecs=speex'>
<source src='audio.oga' type='audio/ogg; codecs=flac'>
<source src='video.ogv' type='video/ogg; codecs="dirac, vorbis"'>
<source src='video.mkv' type='video/x-matroska; codecs="theora, vorbis"'>
The media
attribute gives the intended media type of the media
resource, to help the user agent determine if this
media resource is useful to the user before fetching
it. Its value must be a valid media query.
The default, if the media attribute is omitted, is
"all", meaning that by default the media
resource is suitable for all media.
If the author isn't sure if the user agents will all be able to
render the media resources provided, the author can listen to the
error event on the last
source element and trigger fallback behavior:
<script>
function fallback(video) {
// replace <video> with its contents
while (video.hasChildNodes()) {
if (video.firstChild instanceof HTMLSourceElement)
video.removeChild(video.firstChild);
else
video.parentNode.insertBefore(video.firstChild, video);
}
video.parentNode.removeChild(video);
}
</script>
<video controls autoplay>
<source src='video.mp4' type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src='video.ogv' type='video/ogg; codecs="theora, vorbis"'
onerror="fallback(parentNode)">
...
</video>
track elementISSUE-9 (video-accessibility) blocks progress to Last Call
kindsrccharsetsrclanglabelinterface HTMLTrackElement : HTMLElement {
attribute DOMString kind;
attribute DOMString src;
attribute DOMString charset;
attribute DOMString srclang;
attribute DOMString label;
readonly attribute TimedTrack track;
};
The track element allows authors to specify explicit
external timed tracks for media elements. It does not represent anything on its own.
The kind
attribute is an enumerated attribute. The following
table lists the keywords defined for this attribute. The keyword
given in the first cell of each row maps to the state given in the
second cell.
| Keyword | State | Brief description |
|---|---|---|
subtitles
| Subtitles | Transcription or translation of the dialogue, suitable for when the sound is available but not understood (e.g. because the user does not understand the language of the media resource's soundtrack). |
captions
| Captions | Transcription or translation of the dialogue, sound effects, relevant musical cues, and other relevant audio information, suitable for when the soundtrack is unavailable (e.g. because it is muted or because the user is deaf). |
descriptions
| Descriptions | Textual descriptions of the video component of the media resource, intended for audio synthesis when the visual component is unavailable (e.g. because the user is interacting with the application without a screen while driving, or because the user is blind). |
chapters
| Chapters | Chapter titles, intended to be used for navigating the media resource. |
metadata
| Metadata | Tracks intended for use from script. |
The attribute may be omitted. The missing value default is the subtitles state.
The src attribute
gives the address of the timed track data. The value must be a
valid non-empty URL potentially surrounded by
spaces. This attribute must be present.
If the elements's track URL identifies a
WebSRT resource, and the element's kind attribute is not in the metadata state, then the
WebSRT file must be a WebSRT file using cue
text.
If the elements's track URL identifies a
WebSRT resource, then the charset attribute may
be specified. If the attribute is set, its value must be a valid
character encoding name, must be an ASCII
case-insensitive match for the preferred MIME
name for that encoding, and must match the character encoding
of the WebSRT file. [IANACHARSET]
The srclang
attribute gives the language of the timed track data. The value must
be a valid BCP 47 language tag. This attribute must be present if
the element's kind attribute is
in the subtitles
state. [BCP47]
The label
attribute gives a user-readable title for the track. This title is
used by user agents when listing subtitle, caption, and audio description tracks
in their user interface.
The value of the label
attribute, if the attribute is present, must not be the empty
string. Furthermore, there must not be two track
element children of the same media element whose kind attributes are in the same
state, whose srclang
attributes are both missing or have values that represent the same
language, and whose label
attributes are again both missing or both have the same value.
trackReturns the TimedTrack object corresponding to the timed track of the track element.
This video has subtitles in several languages:
<video src="brave.webm"> <track kind=subtitles src=brave.en.srt srclang=en label="English"> <track kind=captions src=brave.en.srt srclang=en label="English for the Hard of Hearing"> <track kind=subtitles src=brave.fr.srt srclang=fr label="Français"> <track kind=subtitles src=brave.de.srt srclang=de label="Deutsch"> </video>
Media elements
(audio and video, in this specification)
implement the following interface:
interface HTMLMediaElement : HTMLElement {
// error state
readonly attribute MediaError error;
// network state
attribute DOMString src;
readonly attribute DOMString currentSrc;
const unsigned short NETWORK_EMPTY = 0;
const unsigned short NETWORK_IDLE = 1;
const unsigned short NETWORK_LOADING = 2;
const unsigned short NETWORK_NO_SOURCE = 3;
readonly attribute unsigned short networkState;
attribute DOMString preload;
readonly attribute TimeRanges buffered;
void load();
DOMString canPlayType(in DOMString type);
// ready state
const unsigned short HAVE_NOTHING = 0;
const unsigned short HAVE_METADATA = 1;
const unsigned short HAVE_CURRENT_DATA = 2;
const unsigned short HAVE_FUTURE_DATA = 3;
const unsigned short HAVE_ENOUGH_DATA = 4;
readonly attribute unsigned short readyState;
readonly attribute boolean seeking;
// playback state
attribute double currentTime;
readonly attribute double initialTime;
readonly attribute double duration;
readonly attribute Date startOffsetTime;
readonly attribute boolean paused;
attribute double defaultPlaybackRate;
attribute double playbackRate;
readonly attribute TimeRanges played;
readonly attribute TimeRanges seekable;
readonly attribute boolean ended;
attribute boolean autoplay;
attribute boolean loop;
void play();
void pause();
// controls
attribute boolean controls;
attribute double volume;
attribute boolean muted;
// timed tracks
readonly attribute TimedTrack[] tracks;
MutableTimedTrack addTrack(in DOMString kind, in optional DOMString label, in optional DOMString language);
};The media element attributes, src, preload, autoplay, loop, and controls, apply to all media elements. They are defined in
this section.
Media elements are used to present audio data, or video and audio data, to the user. This is referred to as media data in this section, since this section applies equally to media elements for audio or for video. The term media resource is used to refer to the complete set of media data, e.g. the complete video file, or complete audio file.
errorReturns a MediaError object representing the
current error state of the element.
Returns null if there is no error.
interface MediaError {
const unsigned short MEDIA_ERR_ABORTED = 1;
const unsigned short MEDIA_ERR_NETWORK = 2;
const unsigned short MEDIA_ERR_DECODE = 3;
const unsigned short MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
readonly attribute unsigned short code;
};error . codeReturns the current error's error code, from the list below.
MEDIA_ERR_ABORTED (numeric value 1)MEDIA_ERR_NETWORK (numeric value 2)MEDIA_ERR_DECODE (numeric value 3)MEDIA_ERR_SRC_NOT_SUPPORTED (numeric value 4)src attribute was not suitable.The src content
attribute on media elements gives
the address of the media resource (video, audio) to show. The
attribute, if present, must contain a valid non-empty
URL potentially surrounded by spaces.
currentSrcReturns the address of the current media resource.
Returns the empty string when there is no media resource.
There are two ways to specify a media
resource, the src
attribute, or source elements. The attribute overrides
the elements.
A media resource can be described in terms of its
type, specifically a MIME type, in some cases
with a codecs parameter. (Whether the codecs parameter is allowed or not depends on the
MIME type.) [RFC4281]
Types are usually somewhat incomplete descriptions; for example
"video/mpeg" doesn't say anything except what
the container type is, and even a type like "video/mp4; codecs="avc1.42E01E,
mp4a.40.2"" doesn't include information like the actual
bitrate (only the maximum bitrate). Thus, given a type, a user agent
can often only know whether it might be able to play
media of that type (with varying levels of confidence), or whether
it definitely cannot play media of that type.
A type that the user agent knows it cannot render is one that describes a resource that the user agent definitely does not support, for example because it doesn't recognize the container type, or it doesn't support the listed codecs.
The MIME type
"application/octet-stream" with no parameters is never
a type that the user agent knows it cannot render. User
agents must treat that type as equivalent to the lack of any
explicit Content-Type metadata
when it is used to label a potential media
resource.
In the absence of a
specification to the contrary, the MIME type
"application/octet-stream" when used with
parameters, e.g.
"application/octet-stream;codecs=theora", is
a type that the user agent knows it cannot render,
since that parameter is not defined for that type.
canPlayType(type)Returns the empty string (a negative response), "maybe", or "probably" based on how confident the user agent is that it can play media resources of the given type.
This script tests to see if the user agent supports a
(fictional) new format to dynamically decide whether to use a
video element or a plugin:
<section id="video">
<p><a href="playing-cats.nfv">Download video</a></p>
</section>
<script>
var videoSection = document.getElementById('video');
var videoElement = document.createElement('video');
var support = videoElement.canPlayType('video/x-new-fictional-format;codecs="kittens,bunnies"');
if (support != "probably" && "New Fictional Video Plug-in" in navigator.plugins) {
// not confident of browser support
// but we have a plugin
// so use plugin instead
videoElement = document.createElement("embed");
} else if (support == "") {
// no support from browser and no plugin
// do nothing
videoElement = null;
}
if (videoElement) {
while (videoSection.hasChildNodes())
videoSection.removeChild(videoSection.firstChild);
videoElement.setAttribute("src", "playing-cats.nfv");
videoSection.appendChild(videoElement);
}
</script>
The type
attribute of the source element allows the user agent
to avoid downloading resources that use formats it cannot
render.
networkStateReturns the current state of network activity for the element, from the codes in the list below.
NETWORK_EMPTY (numeric value 0)NETWORK_IDLE (numeric value 1)NETWORK_LOADING (numeric value 2)NETWORK_NO_SOURCE (numeric value 3)load()Causes the element to reset and start selecting and loading a new media resource from scratch.
The preload
attribute is an enumerated attribute. The following table
lists the keywords and states for the attribute — the keywords
in the left column map to the states in the cell in the second
column on the same row as the keyword.
| Keyword | State | Brief description |
|---|---|---|
none
| None | Hints to the user agent that either the author does not expect the user to need the media resource, or that the server wants to minimise unnecessary traffic. |
metadata
| Metadata | Hints to the user agent that the author does not expect the user to need the media resource, but that fetching the resource metadata (dimensions, first frame, track list, duration, etc) is reasonable. |
auto
| Automatic | Hints to the user agent that the user agent can put the user's needs first without risk to the server, up to and including optimistically downloading the entire resource. |
The empty string is also a valid keyword, and maps to the Automatic state. The attribute's missing value default is user-agent defined, though the Metadata state is suggested as a compromise between reducing server load and providing an optimal user experience.
The autoplay attribute can override
the preload attribute (since
if the media plays, it naturally has to buffer first, regardless of
the hint given by the preload attribute). Including
both is not an error, however.
bufferedReturns a TimeRanges object that represents the
ranges of the media resource that the user agent has
buffered.
durationReturns the length of the media resource, in seconds, assuming that the start of the media resource is at time zero.
Returns NaN if the duration isn't available.
Returns Infinity for unbounded streams.
currentTime [ = value ]Returns the current playback position, in seconds.
Can be set, to seek to the given time.
Will throw an INVALID_STATE_ERR exception if there
is no selected media resource. Will throw an
INDEX_SIZE_ERR exception if the given time is not
within the ranges to which the user agent can seek.
initialTimeReturns the initial playback position, that is, time to which the media resource was automatically seeked when it was loaded. Returns zero if the initial playback position is still unknown.
The loop
attribute is a boolean attribute that, if specified,
indicates that the media element is to seek back to the
start of the media resource upon reaching the end.
readyStateReturns a value that expresses the current state of the element with respect to rendering the current playback position, from the codes in the list below.
HAVE_NOTHING (numeric value 0)networkState
attribute are set to NETWORK_EMPTY are always in
the HAVE_NOTHING
state.HAVE_METADATA (numeric value 1)video
element, the dimensions of the video are also available. The API
will no longer raise an exception when seeking. No media
data is available for the immediate current playback
position.
The timed tracks
are ready.
HAVE_CURRENT_DATA (numeric value 2)HAVE_METADATA state, or
there is no more data to obtain in the direction of
playback. For example, in video this corresponds to the user
agent having data from the current frame, but not the next frame;
and to when playback has
ended.HAVE_FUTURE_DATA (numeric value 3)HAVE_METADATA
state. For example, in video this corresponds to the user agent
having data for at least the current frame and the next frame. The
user agent cannot be in this state if playback has ended, as the current playback
position can never advance in this case.HAVE_ENOUGH_DATA (numeric value 4)HAVE_FUTURE_DATA state
are met, and, in addition, the user agent estimates that data is
being fetched at a rate where the current playback
position, if it were to advance at the rate given by the
defaultPlaybackRate
attribute, would not overtake the available data before playback
reaches the end of the media resource.It is possible for the ready state of a media
element to jump between these states discontinuously. For example,
the state of a media element can jump straight from HAVE_METADATA to HAVE_ENOUGH_DATA without
passing through the HAVE_CURRENT_DATA and
HAVE_FUTURE_DATA
states.
The autoplay
attribute is a boolean attribute. When present, the
user agent will automatically begin playback of the
media resource as soon as it can do so without
stopping.
Authors are urged to use the autoplay attribute rather than
using script to trigger automatic playback, as this allows the user
to override the automatic playback when it is not desired, e.g. when
using a screen reader. Authors are also encouraged to consider not
using the automatic playback behavior at all, and instead to let the
user agent wait for the user to start playback explicitly.
pausedReturns true if playback is paused; false otherwise.
endedReturns true if playback has reached the end of the media resource.
defaultPlaybackRate [ = value ]Returns the default rate of playback, for when the user is not fast-forwarding or reversing through the media resource.
Can be set, to change the default rate of playback.
The default rate has no direct effect on playback, but if the user switches to a fast-forward mode, when they return to the normal playback mode, it is expected that the rate of playback will be returned to the default rate of playback.
playbackRate [ = value ]Returns the current rate playback, where 1.0 is normal speed.
Can be set, to change the rate of playback.
playedReturns a TimeRanges object that represents the
ranges of the media resource that the user agent has
played.
play()Sets the paused attribute
to false, loading the media resource and beginning
playback if necessary. If the playback had ended, will restart it
from the start.
pause()Sets the paused attribute
to true, loading the media resource if necessary.
seekingReturns true if the user agent is currently seeking.
seekableReturns a TimeRanges object that represents the
ranges of the media resource to which it is possible
for the user agent to seek.
ISSUE-9 (video-accessibility) blocks progress to Last Call
A media element can have a group of associated timed tracks, known as the media element's list of timed tracks. The timed tracks are sorted as follows:
track element children of the media
element, in tree order.addTrack() method, in
the order they were added, oldest first.A timed track consists of:
This decides how the track is handled by the user agent. The kind is represented by a string. The possible strings are:
subtitles
captions
descriptions
chapters
metadata
The kind of track can
change dynamically, in the case of a timed track
corresponding to a track element.
This is a human-readable string intended to identify the track for the user. In certain cases, the label might be generated automatically.
The label of a track can
change dynamically, in the case of a timed track
corresponding to a track element or in the case of an
automatically-generated label whose value depends on variable
factors such as the user's preferred user interface language.
This is a string (a BCP 47 language tag) representing the language of the timed track's cues. [BCP47]
The language of a timed
track can change dynamically, in the case of a timed
track corresponding to a track element.
One of the following:
Indicates that the timed track is known to exist (e.g. it has
been declared with a track element), but its cues
have not been obtained.
Indicates that the timed track is loading and there have been no fatal errors encountered so far. Further cues might still be added to the track.
Indicates that the timed track has been loaded with no fatal
errors. No new cues will be added to the track except if the
timed track corresponds to a
MutableTimedTrack object.
Indicates that the timed track was enabled, but when the user agent attempted to obtain it, this failed in some way (e.g. URL could not be resolved, network error, unknown timed track format). Some or all of the cues are likely missing and will not be obtained.
The readiness state of a timed track changes dynamically as the track is obtained.
One of the following:
Indicates that the timed track is not active. Other than for the purposes of exposing the track in the DOM, the user agent is ignoring the timed track. No cues are active, no events are fired, and the user agent will not attempt to obtain the track's cues.
Indicates that the timed track is active, but that the user agent is not actively displaying the cues. If no attempt has yet been made to obtain the track's cues, the user agent will perform such an attempt momentarily. The user agent is maintaining a list of which cues are active, and events are being fired accordingly.
Indicates that the timed track is active. If no attempt has
yet been made to obtain the track's cues, the user agent will
perform such an attempt momentarily. The user agent is
maintaining a list of which cues are active, and events are
being fired accordingly. In addition, for timed tracks whose
kind is subtitles or captions, the cues
are being displayed over the video as appropriate; for timed
tracks whose kind is descriptions,
the user agent is making the cues available to the user in a
non-visual fashion; and for timed tracks whose kind is chapters, the user
agent is making available to the user a mechanism by which the
user can navigate to any point in the media
resource by selecting a cue.
A list of timed track cues, along with rules for updating the timed track rendering (e.g., for WebSRT, the rules for updating the display of WebSRT timed tracks).
The list of cues of a
timed track can change dynamically, either because the
timed track has not yet been loaded or is still loading, or because the the timed
track corresponds to a MutableTimedTrack
object, whose API allows individual cues can be added or removed
dynamically.
Each timed track has a corresponding
TimedTrack object.
The timed tracks of a media element are ready if all the timed tracks whose mode was not in the disabled state when the element's resource selection algorithm last started now have a timed track readiness state of loaded or failed to load.
A timed track cue is the unit of time-sensitive data in a timed track, corresponding for instance for subtitles and captions to the text that appears at a particular time and disappears at another time.
Each timed track cue consists of:
An arbitrary string.
A time, in seconds and fractions of a second, at which the cue becomes relevant.
A time, in seconds and fractions of a second, at which the cue stops being relevant.
A boolean indicating whether playback of the media resource is to pause when the cue stops being relevant.
A writing direction, either horizontal (a line extends horizontally and is positioned vertically, with consecutive lines displayed below each other), vertical growing left (a line extends vertically and is positioned horizontally, with consecutive lines displayed to the left of each other), or vertical growing right (a line extends vertically and is positioned horizontally, with consecutive lines displayed to the right of each other).
If the writing direction is horizontal, then line position percentages are relative to the height of the video, and text position and size percentages are relative to the width of the video.
Otherwise, line position percentages are relative to the width of the video, and text position and size percentages are relative to the height of the video.
A boolean indicating whether the line's position is a line position (positioned to a multiple of the line dimensions of the first line of the cue), or whether it is a percentage of the dimension of the video.
Either a number giving the position of the lines of the cue, to be interpreted as defined by the writing direction and snap-to-lines flag of the cue, or the special value auto, which means the position is to depend on the other active tracks.
A number giving the position of the text of the cue within each line, to be interpreted as a percentage of the video, as defined by the writing direction.
A number giving the size of the box within which the text of each line of the cue is to be aligned, to be interpreted as a percentage of the video, as defined by the writing direction.
An alignment for the text of each line of the cue, either start alignment (the text is aligned towards its start side), middle alignment (the text is aligned centered between its start and end sides), end alignment (the text is aligned towards its end side). Which sides are the start and end sides depends on the Unicode bidirectional algorithm and the writing direction. [BIDI]
A string identifying the voice with which the cue is associated.
The raw text of the cue, and rules for its interpretation, allowing the text to be rendered and converted to a DOM fragment.
A timed track cue is immutable.
Each timed track cue has a corresponding
TimedTrackCue object, and can be associated with a
particular timed track. Once a timed track
cue is associated with a particular timed track,
the association is permanent.
In addition, each timed track cue has two pieces of dynamic information:
This flag must be initially unset. The flag is used to ensure events are fired appropriately when the cue becomes active or inactive, and to make sure the right cues are rendered.
The user agent must synchronously unset this flag whenever the
timed track cue is removed from its timed
track's timed track list of cues; whenever the
timed track itself is removed from its media
element's list of timed tracks or has its
timed track mode changed to disabled; and whenever the media
element's readyState is changed back to
HAVE_NOTHING. When the
flag is unset in this way for one or more cues in timed tracks that were showing prior to the relevant
incident, the user agent must, after having unset the flag for all
the affected cues, apply the rules for updating the timed
track rendering of those timed
tracks (e.g., for timed
tracks based on WebSRT, the rules for
updating the display of WebSRT timed tracks).
This is used as part of the rendering model, to keep cues in a consistent position. It must initially be empty. Whenever the timed track cue active flag is unset, the user agent must empty the timed track cue display state.
The timed track cues of a media element's timed tracks are ordered relative to each other in the timed track cue order, which is determined as follows: first group the cues by their timed track, with the groups being sorted in the same order as their timed tracks appear in the media element's list of timed tracks; then, within each group, cues must be sorted by their start time, earliest first; then, any cues with the same start time must be sorted by their end time, earliest first; and finally, any cues with identical end times must be sorted in the order they were created (so e.g. for cues from a WebSRT file, that would be the order in which the cues were listed in the file).
A media-resource-specific timed track is a timed track that corresponds to data found in the media resource.
tracks . lengthReturns the number of timed tracks associated with the media element (e.g. from track elements). This is the number of timed tracks in the media element's list of timed tracks.
tracks[ n ]Returns the TimedTrack object representing the nth timed track in the media element's list of timed tracks.
trackReturns the TimedTrack object representing the track element's timed track.
interface TimedTrack {
readonly attribute DOMString kind;
readonly attribute DOMString label;
readonly attribute DOMString language;
const unsigned short NONE = 0;
const unsigned short LOADING = 1;
const unsigned short LOADED = 2;
const unsigned short ERROR = 3;
readonly attribute unsigned short readyState;
readonly attribute Function onload;
readonly attribute Function onerror;
const unsigned short OFF = 0;
const unsigned short HIDDEN = 1;
const unsigned short SHOWING = 2;
attribute unsigned short mode;
readonly attribute TimedTrackCueList cues;
readonly attribute TimedTrackCueList activeCues;
readonly attribute Function oncuechange;
};kindReturns the timed track kind string.
labelReturns the timed track label.
languageReturns the timed track language string.
readyStateReturns the timed track readiness state, represented by a number from the following list:
TimedTrack . NONE (0)The timed track not loaded state.
TimedTrack . LOADING (1)The timed track loading state.
TimedTrack . LOADED (2)The timed track loaded state.
TimedTrack . ERROR (3)The timed track failed to load state.
modeReturns the timed track mode, represented by a number from the following list:
TimedTrack . OFF (0)The timed track disabled mode.
TimedTrack . HIDDEN (0)The mode.
TimedTrack . SHOWING (0)The timed track showing mode.
Can be set, to change the mode.
cuesReturns the timed track list of cues, as a TimedTrackCueList object.
activeCuesReturns the timed track cues from the timed track list of cues that are currently active (i.e. that start before the current playback position and end after it), as a TimedTrackCueList object.
interface MutableTimedTrack : TimedTrack {
void addCue(in TimedTrackCue cue);
void removeCue(in TimedTrackCue cue);
};addTrack( kind [, label [, language ] ] )Creates and returns a new MutableTimedTrack object, which is also added to the media element's list of timed tracks.
addCue( cue )Adds the given cue to mutableTimedTrack's timed track list of cues.
Raises an exception if the argument is null, associated with another timed track, or already in the list of cues.
removeCue( cue )Removes the given cue from mutableTimedTrack's timed track list of cues.
Raises an exception if the argument is null, associated with another timed track, or not in the list of cues.
In this example, an audio element is used to play a
specific sound-effect from a sound file containing many sound
effects. A cue is used to pause the audio, so that it ends exactly
at the end of the clip, even if the browser is busy running some
script. If the page had relied on script to pause the audio, then
the start of the next clip might be heard if the browser was not
able to run the script at the exact time specified.
var sfx = new Audio('sfx.wav');
var sounds = a.addTrack('metadata');
// add sounds we care about
sounds.addCue(new TimedTrackCue('dog bark', 12.783, 13.612, '', '', '', true));
sounds.addCue(new TimedTrackCue('kitten mew', 13.612, 15.091, '', '', '', true));
function playSound(id) {
sfx.currentTime = sounds.getCueById(id).startTime;
sfx.play();
}
sfx.oncanplaythrough = function () {
playSound('dog bark');
}
window.onbeforeunload = function () {
playSound('kitten mew');
return 'Are you sure you want to leave this awesome page?';
}
interface TimedTrackCueList {
readonly attribute unsigned long length;
getter TimedTrackCue (in unsigned long index);
TimedTrackCue getCueById(in DOMString id);
};lengthReturns the number of cues in the list.
Returns the timed track cue with index index in the list. The cues are sorted in timed track cue order.
getCueById( id )Returns the first timed track cue (in timed track cue order) with timed track cue identifier id.
Returns null if none of the cues have the given identifier or if the argument is the empty string.
[Constructor(in DOMString id, in double startTime, in double endTime, in DOMString text, in optional DOMString settings, in optional DOMString voice, in optional boolean pauseOnExit)]
interface TimedTrackCue {
readonly attribute TimedTrack track;
readonly attribute DOMString id;
readonly attribute double startTime;
readonly attribute double endTime;
readonly attribute boolean pauseOnExit;
readonly attribute DOMString direction;
readonly attribute boolean snapToLines;
readonly attribute long linePosition;
readonly attribute long textPosition;
readonly attribute long size;
readonly attribute DOMString alignment;
readonly attribute DOMString voice;
DOMString getCueAsSource();
DocumentFragment getCueAsHTML();
readonly attribute Function onenter;
readonly attribute Function onexit;
};TimedTrackCue( id, startTime, endTime, text [, settings [, voice [, pauseOnExit ] ] ] )Returns a new TimedTrackCue object, for use with the addCue() method.
The id argument sets the timed track cue identifier.
The startTime argument sets the timed track cue start time.
The endTime argument sets the timed track cue end time.
The text argument sets the timed track cue text.
The settings argument is a string in the format of WebSRT cue settings. If omitted, the empty string is assumed.
The voice argument sets the timed track cue voice identifier. If omitted, the empty string is assumed.
The pauseOnExit argument sets the timed track cue pause-on-exit flag. If omitted, false is assumed.
Returns the TimedTrack object to which this
timed track cue belongs, if any, or null
otherwise.
Returns the timed track cue identifier.
Returns the timed track cue start time, in seconds.
Returns the timed track cue end time, in seconds.
Returns true if the timed track cue pause-on-exit flag is set, false otherwise.
Returns a string representing the timed track cue writing direction, as follows:
The string "horizontal".
The string "vertical".
The string "vertical-lr".
Returns true if the timed track cue snap-to-lines flag is set, false otherwise.
Returns the timed track cue line position. In the case of the value being auto, the appropriate default is returned.
Returns the timed track cue text position.
Returns the timed track cue size.
Returns a string representing the timed track cue alignment, as follows:
The string "start".
The string "middle".
The string "end".
Returns the timed track cue voice identifier.
Returns the timed track cue text in raw unparsed form.
Returns the timed track cue text as a DocumentFragment of HTML elements and other DOM nodes.
The controls
attribute is a boolean attribute. If present, it
indicates that the author has not provided a scripted controller and
would like the user agent to provide its own set of controls.
volume [ = value ]Returns the current playback volume, as a number in the range 0.0 to 1.0, where 0.0 is the quietest and 1.0 the loudest.
Can be set, to change the volume.
Throws an INDEX_SIZE_ERR if the new value is not
in the range 0.0 .. 1.0.
muted [ = value ]Returns true if audio is muted, overriding the volume attribute, and false if the
volume attribute is being
honored.
Can be set, to change whether the audio is muted or not.
The audio
attribute on the video element controls the default
state of the audio channel of the media resource,
potentially overriding user preferences.
The audio attribute, if
specified, must have a value that is an unordered set of
unique space-separated tokens, which are ASCII
case-insensitive. The tokens must be from the following list
(currently, only one allowed token is defined):
mutedCauses the user agent to override the user's preferences, if any, and always default the video to muted.
A future version of this specification will probably introduce new values here, e.g. to control the default volume, or to select a default audio track.
This attribute has no dynamic effect (it only controls the default state of the element).
This video (an advertisment) autoplays, but to avoid annoying users, it does so without sound, and allows the user to turn the sound on.
<video src="adverts.cgi?kind=video" controls autoplay loop audio=muted></video>
Objects implementing the TimeRanges interface
represent a list of ranges (periods) of time.
interface TimeRanges {
readonly attribute unsigned long length;
double start(in unsigned long index);
double end(in unsigned long index);
};lengthReturns the number of ranges in the object.
start(index)Returns the time for the start of the range with the given index.
Throws an INDEX_SIZE_ERR if the index is out of range.
end(index)Returns the time for the end of the range with the given index.
Throws an INDEX_SIZE_ERR if the index is out of range.
This section is non-normative.
The following events fire on media elements as part of the processing model described above:
| Event name | Interface | Dispatched when... | Preconditions |
|---|---|---|---|
loadstart
| Event
| The user agent begins looking for media data, as part of the resource selection algorithm. | networkState equals NETWORK_LOADING
|
progress
| Event
| The user agent is fetching media data. | networkState equals NETWORK_LOADING
|
suspend
| Event
| The user agent is intentionally not currently fetching media data, but does not have the entire media resource downloaded. | networkState equals NETWORK_IDLE
|
abort
| Event
| The user agent stops fetching the media data before it is completely downloaded, but not due to an error. | error is an object with the code MEDIA_ERR_ABORTED.
networkState equals either NETWORK_EMPTY or NETWORK_IDLE, depending on when the download was aborted.
|
error
| Event
| An error occurs while fetching the media data. | error is an object with the code MEDIA_ERR_NETWORK or higher.
networkState equals either NETWORK_EMPTY or NETWORK_IDLE, depending on when the download was aborted.
|
emptied
| Event
| A media element whose networkState was previously not in the NETWORK_EMPTY state has just switched to that state (either because of a fatal error during load that's about to be reported, or because the load() method was invoked while the resource selection algorithm was already running).
| networkState is NETWORK_EMPTY; all the IDL attributes are in their initial states.
|
stalled
| Event
| The user agent is trying to fetch media data, but data is unexpectedly not forthcoming. | networkState is NETWORK_LOADING.
|
play
| Event
| Playback has begun. Fired after the play() method has returned, or when the autoplay attribute has caused playback to begin.
| paused is newly false.
|
pause
| Event
| Playback has been paused. Fired after the pause() method has returned.
| paused is newly true.
|
loadedmetadata
| Event
| The user agent has just determined the duration and dimensions of the media resource and the timed tracks are ready. | readyState is newly equal to HAVE_METADATA or greater for the first time.
|
loadeddata
| Event
| The user agent can render the media data at the current playback position for the first time. | readyState newly increased to HAVE_CURRENT_DATA or greater for the first time.
|
waiting
| Event
| Playback has stopped because the next frame is not available, but the user agent expects that frame to become available in due course. | readyState is newly equal to or less than HAVE_CURRENT_DATA, and paused is false. Either seeking is true, or the current playback position is not contained in any of the ranges in buffered. It is possible for playback to stop for two other reasons without paused being false, but those two reasons do not fire this event: maybe playback ended, or playback stopped due to errors.
|
playing
| Event
| Playback has started. | readyState is newly equal to or greater than HAVE_FUTURE_DATA, paused is false, seeking is false, or the current playback position is contained in one of the ranges in buffered.
|
canplay
| Event
| The user agent can resume playback of the media data, but estimates that if playback were to be started now, the media resource could not be rendered at the current playback rate up to its end without having to stop for further buffering of content. | readyState newly increased to HAVE_FUTURE_DATA or greater.
|
canplaythrough
| Event
| The user agent estimates that if playback were to be started now, the media resource could be rendered at the current playback rate all the way to its end without having to stop for further buffering. | readyState is newly equal to HAVE_ENOUGH_DATA.
|
seeking
| Event
| The seeking IDL attribute changed to true and the seek operation is taking long enough that the user agent has time to fire the event.
| |
seeked
| Event
| The seeking IDL attribute changed to false.
| |
timeupdate
| Event
| The current playback position changed as part of normal playback or in an especially interesting way, for example discontinuously. | |
ended
| Event
| Playback has stopped because the end of the media resource was reached. | currentTime equals the end of the media resource; ended is true.
|
ratechange
| Event
| Either the defaultPlaybackRate or the playbackRate attribute has just been updated.
| |
durationchange
| Event
| The duration attribute has just been updated.
| |
volumechange
| Event
| Either the volume attribute or the muted attribute has changed. Fired after the relevant attribute's setter has returned.
|