Turning off closed caption on HTML5 video by default

左心房为你撑大大i 提交于 2019-12-13 16:26:53

问题


Here's what I have...

<video id="video" controls="controls" preload="metadata" poster="/video/promotional/transparent.png">
    <source src="/video/promotional/promotional.mp4" type="video/mp4" />
    <source src="/video/promotional/promotional.webm" type="video/webm" />
    <source src="/video/promotional/promotional.ogv" type="video/ogg" />
    <track src="/video/promotional/promotional.vtt" label="English Captions" kind="subtitles" srclang="en-us" />
</video>

<script type="text/javascript">
    $(document).ready(function() {
        var video = document.querySelector('#video');
        var.track = video.textTracks[0];
        track.mode = 'hidden';
    });
</script>

I was hoping this would turn off closed caption by default, but it doesn't seem to be the case. Any ideas?


回答1:


your answer was very close (I assume var.track = was a typo - fixing that works in Chrome and Safari on OSX and IE on PC for me). For re-use I like to split the textTracks out into a variable, but that's personal preference:

<script type="text/javascript">
    $(document).ready(function() {
    var video = document.querySelector('#video'); // get the video element
    var tracks = video.textTracks; // one for each track element
    var track = tracks[0]; // corresponds to the first track element
    track.mode = 'hidden';
});



来源:https://stackoverflow.com/questions/20648184/turning-off-closed-caption-on-html5-video-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!