从视频中删除TextTrack [英] Delete a TextTrack from a video
问题描述
是否有删除单个 TextTrack
是否通过JavaScript添加到HTML5 <video>
标签?以下代码是如何添加曲目的简单演示,但我还没有找到删除曲目的好方法:
Is there a good way to delete a single TextTrack
added via JavaScript to a HTML5 <video>
tag? The following code is a simple demo of how to add a track, but I haven't found a good way to remove one:
document.querySelector('video#myVideo').addTextTrack(...);
推荐答案
在当前规范中,没有机制来删除添加的文本轨道(可能是缺陷(?),但是还有一个onremovetrack
事件. ..).
There is no mechanism to remove an added text-track (probably a flaw (?) in the current specification. There is also an onremovetrack
event but...).
我们唯一可以做的就是禁用或隐藏它.确保保留对曲目的引用:
The only thing we can do is to disable or hide it. Make sure you keep a reference to the track:
var video = document.querySelector('video#myVideo');
var track = video.addTextTrack("...");
...
track.mode = "showing"; // when cues are added and is ready
然后,当您不再需要它时:
Then when you no longer need it:
track.mode = "disabled"; // or "hidden"
(您也可能会重置src,但我没有尝试过此操作.)
(you might get around resetting the src as well, but I haven't tried this..)
这篇关于从视频中删除TextTrack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!