Web 接口
VTTCue - 描述并控制与特定 <track> 元素关联的文本轨道
实例
源代码:
点击运行 »
<style> video { width: 320px; height: 180px; } </style> <video controls src="/examples/movie.mp4"></video> <script> let video = document.querySelector('video'); video.addEventListener('loadedmetadata', () => { const track = video.addTextTrack("captions", "简体中文Subtitles", "zh_CN"); track.mode = "showing"; const cueCn = new VTTCue(0, 2.500, '字幕会在0至2.5秒间显示'); track.addCue(cueCn); const cueEn = new VTTCue(2.6, 4, 'Subtitles will display between 2.6 and 4 seconds'); track.addCue(cueEn); }); </script>
运行结果:
点击运行 »