video.js icon indicating copy to clipboard operation
video.js copied to clipboard

Default flag not working on tracks (subtitles, captions)

Open engamaraziz opened this issue 13 years ago • 7 comments

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.

engamaraziz avatar Jul 26 '13 03:07 engamaraziz

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

heff avatar Jul 29 '13 15:07 heff

A fix of that bug (or a public function to enable the track via js) would be greatly appreciated! Thanks!

sikoried avatar Oct 03 '13 16:10 sikoried

+1

smoreau avatar Oct 23 '13 07:10 smoreau

No! No! And no! It's impossible! I uncomment this code, heff and...

123

salmazov avatar Oct 31 '13 09:10 salmazov

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 avatar Dec 27 '13 15:12 Korotkiewicz

@Korotkiewicz thanks a lot it worked for me...

akitrav avatar Jan 14 '14 10:01 akitrav

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());
}

Chris-DL avatar Apr 16 '14 17:04 Chris-DL