TextTrack interface—part of the API for handling WebVTT (text tracks on media presentations)—describes and controls the text track associated with a particular <track> 元素。

特性

This interface also inherits properties from EventTarget .

TextTrack.activeCues 只读
TextTrackCueList object listing the currently active set of text track cues. Track cues are active if the current playback position of the media is between the cues' start and end times. Thus, for displayed cues such as captions or subtitles, the active cues are currently being displayed.
TextTrack.cues 只读
TextTrackCueList which contains all of the track's cues.
TextTrack.id 只读
DOMString which identifies the track, if it has one. If it doesn't have an ID, then this value is an empty string ( "" ). If the TextTrack is associated with a <track> element, then the track's ID matches the element's ID.
TextTrack.inBandMetadataTrackDispatchType 只读
返回 DOMString which indicates the track's in-band metadata track dispatch type. needs details
TextTrack.kind 只读
返回 DOMString indicating what kind of text track the TextTrack describes. The value must be one of those in the TextTrackKind enum.
TextTrack.label 只读
A human-readable DOMString which contains the text track's label, if one is present; otherwise, this is an empty string ( "" ), in which case a custom label may need to be generated by your code using other attributes of the track, if the track's label needs to be exposed to the user.
TextTrack.language 只读
DOMString which specifies the text language in which the text track's contents is written. The value must adhere to the format specified in the Tags for Identifying Languages ( BCP 47 ) document from the IETF, just like the HTML lang attribute. For example, this can be "en-US" for United States English or "pt-BR" for Brazilian Portuguese.
TextTrack.mode
DOMString specifying the track's current mode. Changing this property's value changes the track's current mode to match. Permitted values are listed under Text track mode constants 。默认为 被禁用 , unless the <track> 元素的 default Boolean attribute is specified, in which case the default mode is started .

事件

cuechange
Fired when cues are entered and exited. A given text cue appears when the cue is entered and disappears when the cue is exited.
也可用凭借 oncuechange 特性。

方法

This interface also inherits methods from EventTarget .

TextTrack.addCue()
Adds a cue (specified as a TextTrackCue object to the track's list of cues.
TextTrack.removeCue()
Removes a cue (specified as a TextTrackCue object from the track's list of cues.

范例

tbd

规范

规范 状态 注释
HTML 实时标准
The definition of 'TextTrack' in that specification.
实时标准

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
TextTrack Chrome 18 Edge 12 Firefox 31
31
Firefox versions before Firefox 50 didn't display captions when playing media without one or more video tracks being played.
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
activeCues Chrome 18 Edge 12 Firefox 31
31
Starting in Firefox 69, cues are no longer incorrectly loaded when the TextTrack 's mode is 被禁用 ; if that's the case, the returned list is empty.
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
addCue 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
cuechange event Chrome Yes Edge 12 Firefox 31 IE ? Opera ? Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 31 Opera Android No Safari iOS ? Samsung Internet Android Yes
cues Chrome 18 Edge 12 Firefox 31
31
Starting in Firefox 69, cues are no longer incorrectly loaded when the TextTrack 's mode is 被禁用 ; if that's the case, the returned list is empty.
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
id 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
inBandMetadataTrackDispatchType 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
kind 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
label 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
语言 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
mode Chrome 18 Edge 12 Firefox 31
31
Before Firefox 52, using JavaScript to change the mode of a text track that's part of a media element would send one change event to the element's textTracks TextTrackList for each change, even if mutliple changes are made in a single pass through the Firefox event loop. Starting in Firefox 52, these changes are reflected by a single event.
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
oncuechange Chrome Yes Edge 12 Firefox 31 IE ? Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 31 Opera Android No Safari iOS ? Samsung Internet Android Yes
removeCue 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
sourceBuffer Chrome No Edge No Firefox ? IE ? Opera ? Safari Yes WebView Android No Chrome Android No Firefox Android ? Opera Android No Safari iOS ? Samsung Internet Android No

图例

完整支持

完整支持

不支持

不支持

兼容性未知 ?

兼容性未知

见实现注意事项。

另请参阅

元数据

  • 最后修改:
  1. WebVTT API
  2. TextTrack
  3. 特性
    1. mode
  4. 事件
    1. cuechange
  5. 继承:
    1. EventTarget
  6. Related pages for WebVTT
    1. TextTrackCue
    2. TextTrackCueList
    3. TextTrackList
    4. TrackEvent
    5. VTTCue
    6. VTTRegion

版权所有  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1