I am using Video.js for a customized video player and by default it shows the captions when video starts playing. How can I have the closed captions disabled on start/autoplay?
var myPlayer = _V_("myPlayer");
var videoPlaying = true;
// video captions button
var myCaption = myPlayer.controlBar.addChild("button");
// Styling to empty button
$(".vjs-control-text").empty();
// Add class to captions
myCaption.addClass("vjs-captions-icon");
myCaption.addClass("vjs-captions-icon-on");
// Adding functionality to captions button
$(".vjs-captions-icon").on('touchstart', function() {
$('div.vjs-captions.vjs-text-track').toggle();
$('.vjs-control-bar .vjs-captions-icon').toggleClass('vjs-captions-icon-on').toggleClass('vjs-captions-icon-off');
});
.vjs-captions-icon-on {
background: url(../img/caption_button.png);
background-size: 100% 100%;
}
.vjs-captions-icon-off {
background: url(../img/caption_button_off.png);
background-size: 100% 100%;
}
<video id="myPlayer" class="video-js vjs-sublime-skin" width="1024px" height="768px" controls autoplay preload data-setup='{"nativeControlsForTouch": false}'>
<source src="../video/brandt.mp4" type='video/mp4' />
<track class="caption" kind="captions" src="../video/brandt.vtt" type="text/plain" srclang="en" label="English" default/>
</video>
Sharing answer from gkatsev answered here https://github.com/videojs/video.js/issues/2124
Quoting from there.
showing - the text track is visible and updating and firing events
disabled - the track track isn't visible and isn't firing events
hidden - the track track isn't visible but it is firing events.So, to hide a track, you can do:
player.textTracks()[0].mode = 'disabled';