Default flag not working on tracks (subtitles, captions)
The default subtitles are not showing when the video is played. However, it works correctly when choosing it form the menu.
Here's my code:
<video id="intro" class="video-js vjs-default-skin" controls
preload="auto" width="500" height="300" poster="xxx.png"
data-setup="{}">
<source src="xxx.mp4" type='video/mp4'>
<source src="xxx.webm" type='video/webm'>
<track kind="subtitles" src="xxx.vtt" srclang="fr" label="French" default>
</video>
Is it a bug or I am doing something wrong?
Upon Googling the issue I found some people are facing the same issue.
Please help.
It looks like there's a partial implementation that could be un-commented. Needs to be tested. https://github.com/videojs/video.js/blob/v4.1.0/src/js/tracks.js#L60
A fix of that bug (or a public function to enable the track via js) would be greatly appreciated! Thanks!
+1
No! No! And no! It's impossible! I uncomment this code, heff and...
I solved this problem by modifying method vjs.TextTrackMenuItem (line: 6666):
vjs.TextTrackMenuItem = vjs.MenuItem.extend({
/** @constructor */
init: function(player, options){
var track = this.track = options['track'];
// Modify options for parent MenuItem class's init.
options['label'] = track.label();
options['selected'] = track.dflt();
vjs.MenuItem.call(this, player, options);
this.player_.on(track.kind() + 'trackchange', vjs.bind(this, this.update));
/**
* @author Michal Korotkiewicz
* my modification:
*/
if(track.dflt()) {
this.player_.showTextTrack(this.track.id_, this.track.kind());
}
}
});
@Korotkiewicz thanks a lot it worked for me...
Thanks @Korotkiewicz, for tracking this down and posting a workable solution to the issue. However, I did not see a pull request for the fix, so I took a second look and found that it was failing one of the unit tests. I tracked this down to the player.js test where it checks the validity of the player and associated tracks. I believe the test failed because (with the newly added fix) there is no external file to pull the content from on default, hence the failure. Adding an additional check to see if the video was set to auto preload is one possible solution.
this.player_.on(track.kind() + 'trackchange', vjs.bind(this, this.update));
/**
* Add additional check parameter for auto preload
*/
var preload = player.options_['preload'];
if(track.dflt() && preload === 'auto') {
this.player_.showTextTrack(this.track.id_, this.track.kind());
}