HTMLMediaElement对象上的只读textTracks属性返回一个TextTrackList对象,该对象列出所有代表媒体元素文本轨道的TextTrack对象,其顺序与文本轨道列表中的顺序相同。
获得可用文本轨道的数量:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML 音频/视频 textTracks 属性使用-菜鸟教程(cainiaojc.com)</title>
</head>
<body>
<button onclick="getTextTracks()" type="button">获得可用文本轨道的数量</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">
您的浏览器不支持 HTML5 video 标签。
</video>
<script>
myVid=document.getElementById("video1");
function getTextTracks()
{
alert(myVid.textTracks.length);
}
</script>
</body>
</html>
测试看看 ‹/›textTracks属性返回一个TextTrackList对象。
TextTrackList对象代表音频/视频的可用文本轨道。
每个可用的文本轨道都由一个TextTrack对象表示。
IEFirefoxOperaChromeSafari
Internet Explorer 10、Opera、Chrome 和 Safari 6 支持 textTracks 属性。
注意:Internet Explorer 9 及之前的版本不支持 textTracks 属性。
audio|video.textTracks
类型 | 描述 |
---|---|
TextTrackList 对象 | 表示音频/视频的可用文本轨道。 TextioTrackList 对象:
注释:第一个可用文本轨道的下标 index 是 0。 |
TextTrack 对象 | 表示一个文本轨道。 TextTrack 对象的属性:
|