gpt4 book ai didi

javascript - 使用

转载 作者:行者123 更新时间:2023-12-03 04:56:47 25 4
gpt4 key购买 nike

如何使用<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>

最佳答案

根据轨道的文档,我认为您想要的内容如下所示:

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

此外,这里有一个关于使用轨道的完整教程:https://www.html5rocks.com/en/tutorials/track/basics/

关于javascript - 使用 <video> 和 <track>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42397719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com