English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML-Referenzhandbuch

Komplettes Verzeichnis der HTML-Tags

HTML Audio/Video-DOM-Attribut textTracks

Das read-only-Attribut textTracks des HTMLMediaElement-Objekts gibt eine TextTrackList-Instanz zurück, die alle TextTrack-Objekte auflistet, die die Textspuren des Medienelements darstellen, in der Reihenfolge, in der sie in der Textspur-Liste stehen.

 HTML Audio/Video DOM Reference Manual

Online example

Get the number of available text tracks:

!DOCTYPE html
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/Video textTracks attribute usage-Basic tutorial(oldtoolbag.com)</<title>
</<head>
<body>
<button onclick="getTextTracks()" type="button">Get the number of available text tracks</button>
<br> 
<video id="video1" controls="controls">
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  <track src="demo_sub.vtt">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1");
function getTextTracks()
{ 
  alert(myVid.textTracks.length);
} 
</script>
</body>
</html>
Test to see ‹/›

Definition and usage

The textTracks property returns a TextTrackList object.
The TextTrackList object represents audio/The available text tracks of the video.
Each available text track is represented by a TextTrack object.

Browser compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10Opera, Chrome and Safari 6 Supports the textTracks attribute.

Note:Internet Explorer 9 And earlier versions do not support the textTracks attribute.

Syntax

audio|video.textTracks

Return value

TypeDescription
TextTrackList objectRepresents audio/The available text tracks of the video.

TextioTrackList object:

  • length - Get audio/The number of available text tracks in the video

  • [index] - According to the index index to obtain the TextTrack object

Note:Index of the first available text track index is 0.

TextTrack objectRepresents a text track.

Properties of the TextTrack object:

  • kind - Get the type of the text track (can be "subtitles", "caption", "descriptions", "chapters", or "metadata")

  • label - Get the label of the text track

  • language - Get the language of the text track

  • mode - Get or set whether the track is active ("disabled"|"hidden"|"showing")

  • cues - Get the cues list of the TextTrackCueList object

  • activeCues - Get the current active text track cues in the form of a TextTrackCueList object

  • addCue(cue) - Add a cue to the cues list

  • removeCue(cue) - Remove a cue from the cues list

 HTML Audio/Video DOM Reference Manual