Skip to content

Instantly share code, notes, and snippets.

@jtwalters
Last active November 19, 2015 00:07
Show Gist options
  • Save jtwalters/52438d2256cefbbd3dba to your computer and use it in GitHub Desktop.
Save jtwalters/52438d2256cefbbd3dba to your computer and use it in GitHub Desktop.
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
window.videojs.plugin('autoCaptions', function () {
var player = this,
langMap = {
'de-de': 'German',
'es-es': 'Spanish',
'fr-fr': 'French',
'ja-jp': 'Japanese',
'ko-kr': 'Korean',
'pt-br': 'Portuguese',
'zh-cn': 'Chinese'
},
options = player.options(),
dataCaptionsLang = options['data-captions-lang'],
langParam = getParameterByName('_lang'),
lang = langMap[dataCaptionsLang || langParam] || false,
captions;
player.on('play', function () {
captions = player.textTracks();
for (var i = 0; i < captions.length; i++) {
if (lang === captions[i].language) {
captions[i].mode = 'showing';
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment