如何在视频中使用<track>?当鼠标放在这个单词上时,我想从跟踪文本中获取单词。
var track = document.getElementById('ger').track;
var cues = track.cues;
var active_cues = track.activeCues;
var text = active_cues[0].text;
console.log(text);<video id="video" width="320" height="240" controls>
<source src="Video/video.mp4" type='video/mp4'>
<track id="ger" kind="subtitles" src="Video/Twitter_in_Plain_English_ger.vtt" srclang="de">
</video>
发布于 2017-03-21 06:31:14
基于曲目的文档,我认为你想要的应该是这样的:
var videoElement = document.querySelector("video");//get video element where you want tracks
var track = videoElement.textTracks[0]; //get first track element that contains cues
var activeCue = track.activeCues[0]; //get first active cue
var cueText = activeCue.text; // get the text of active cue
console.log(cueText); display text in dev console此外,这里有一个很好的完整教程,介绍如何使用tracks:https://www.html5rocks.com/en/tutorials/track/basics/
https://stackoverflow.com/questions/42397719
复制相似问题