TextTrack
接口的
mode
property is a string specifying and controlling the text track's mode:
被禁用
,
hidden
,或
showing
.
You can read this value to determine the current mode, and you can change this value to switch modes.
Safari additionally requires the
default
boolean attribute to be set to true when implementing your own video player controls in order for the subtitles cues to be shown.
var mode = textTrack.mode; textTrack.mode = "disabled" | "hidden" | "showing";
A
DOMString
which indicates the track's current mode. The text track mode is one of the values listed below, under
Text track mode constants
.
The text track mode—sometimes identified using the IDL enum
TextTrackMode
—must be one of the following values:
被禁用
default
Boolean attribute is specified, in which case the default is
showing
.
hidden
TextTrack.cues
property). The user agent is keeping a list of the active cues (in the track's
activeCues
property) and events are being fired at the corresponding times, even though the text isn't being displayed.
showing
activeCues
list is being maintained and events are firing at the appropriate times; the track's text is also being drawn appropriately based on the styling and the track's
kind
. This is the default value if the text track's
default
Boolean attribute is specified.
默认
mode
is
被禁用
, unless the
default
Boolean attribute is specified, in which case the default
mode
is
showing
. When a text track is loaded in the
被禁用
state, the corresponding WebVTT file is not loaded until the state changes to either
showing
or
hidden
. This way, the resource fetch and memory usage are avoided unless the cues are actually needed.
However, that means that if you wish to perform any actions involving the track's cues while handling, for example, the
load
event—in order to process some aspect of the cues upon page load—and the track mode was initially
被禁用
, you'll have to change the
mode
到
hidden
or
showing
in order to trigger loading of the cues.
When the mode is
showing
, text tracks are performed. The exact appearance and manner of that performance varies depending on each text track's
kind
. In general:
kind
is
"subtitles"
or
"captions"
are rendered with the cues overlaid over the top of the video.
kind
is
"descriptions"
are presented in a non-visual form (for example, the text might be spoken to describe the action in the video).
kind
is
"chapters"
are used by the user agent or the Web site or Web app to construct and present an interface for navigating the named chapters, where each cue in the list represents a chapter in the media. The user can then navigate to the desired chapter, which begins at the cue's start position and ends at the cue's end position.
In this example, we configure the text track's cues so that every time a cue is finished, the video automatically pauses playback. This is done by setting the
pauseOnExit
property on each cue to
true
. However, to ensure that the track's cues are available, we first set
mode
to
showing
.
window.addEventListener("load", event => {
let trackElem = document.querySelector("track");
let track = trackElem.track;
track.mode = "showing";
for (let index=0; index < track.cues.length; index++) {
let cue = track.cues[index];
cue.pauseOnExit = true;
};
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
HTML 实时标准
The definition of 'mode' in that specification. |
实时标准 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mode
|
Chrome 18 | Edge 12 |
Firefox
31
注意事项
|
IE 10 | Opera 15 | Safari 6 | WebView Android 4.4 | Chrome Android 18 | Firefox Android 31 | Opera Android 不支持 No | Safari iOS 7 | Samsung Internet Android 1.0 |
完整支持
不支持
见实现注意事项。
TextTrack
mode