3

I'm trying to build some thing like a video gallery which you can select a video to show up by clicking on its thumbnail. Now I'm at phase of loading appropriate subtitles for the chosen video. Thanks to google I understand that videojs has a method to help me called addTextTrack() but unfortunately there is not a good sample or documentation for it. After all I tried to find its parameters and behavior via reading the video.dev.js codes. but as I understand this method has just three params (kind, label, language) and the thing that I didn't understand is that: How can I set the src to load the subtitle file. I think its a bug and it doesn't work properly and I want to report it if you're agree with me.

The following code adds cc icon to the player but it doesn't show the subtitle (How can it be shown when I didn't tell him the URL to load)

var myPlayer = videojs('video-id');
myPlayer.addTextTrack('captions', 'En', 'English');

I checked videojs 5.0.0 addTextTrack method and there wasn't any significant changes.

mahyard
  • 1,230
  • 1
  • 13
  • 34

2 Answers2

6

After about a month without any answer to my question, I don't know yet why addTextTrack() doesn't work properly. But thanks God, I found a way to achieve my goal:

To dynamically changing all text tracks

var oldTracks = player.remoteTextTracks();
var i = oldTracks.length;
while (i--) {
  player.removeRemoteTextTrack(oldTracks[i]);
}
myNewTracks.forEach(function(track) {
  player.addRemoteTextTrack(track);
});
mahyard
  • 1,230
  • 1
  • 13
  • 34
  • Hi, thanks for your example. I'm running into the same issue. I'm still not sure how to load the proper src url track, have you got a longer example, maybe? Thanks! – Lucien S. Dec 20 '17 at 14:47
  • you are welcome @rodolphe , Sorry I don't have a longer example – mahyard Dec 21 '17 at 12:40
3

The text track did never get updated dynamically and after a long search, I had found a solution for my problem. When I change the video source I replace the text track and set it on mode="showing":

let player = videojs('first-player');
player.addRemoteTextTrack({
            kind: 'captions',
            src: 'my-track-path.vtt',
            mode: 'showing'
}, false);
Numb3rs
  • 101
  • 9