jaruba / wcjs-player

Node Player made for WebChimera.js (libVLC wrapper)
http://webchimera.org/
GNU Lesser General Public License v2.1
178 stars 46 forks source link

Select a subtitle on load #15

Closed siuying closed 9 years ago

siuying commented 9 years ago

Can I set subtitles programmatically? This is how I add subtitle:

var params = {url: "the-url", subtitles: {"English": "subs-url"}}
var player = new wjs("#player").addPlayer({ autoplay: true });
player.addPlaylist(params)

However, this would only add the subtitles to video, not activate them. User would have to manually select the subs from menu.

Adding subTrack() do not seems help (it would work if the video is loaded and i run it in console)

player.subTrack(1)
jaruba commented 9 years ago
var params = {url: "the-url", subtitles: {"English": "subs-url"}},
    player = new wjs("#player").addPlayer({ autoplay: true }),
    firstTime = true;

player.onMediaChanged(function() { firstTime = true; });
player.onEnded(function() { firstTime = true; });
player.onStopped(function() { firstTime = true; });

player.onPlaying(function() {
    if (firstTime) {
        firstTime = false;
        player.subTrack(1);
    }
});

player.addPlaylist(params);
siuying commented 9 years ago

Thanks! that's what I needed.

jaruba commented 9 years ago

make sure you use the latest example code i posted in the comment (i changed it a few times), also there might be better ways to do it, this is just the first way I thought of..

siuying commented 9 years ago

got it! 👍