My page contains this <video>
tag with several subtitle <track>
s. I would like to enable on the fly the track by clicking on the corresponding national flag using jquery:
<div id="lang">
<img src="mini/ita.png" class="it" alt="Italiano" title="Italiano" />
<img src="mini/eng.png" class="en" alt="English" title="English" />
</div>
<video controls="controls" >
<source src="webcast.webm" />
<source src="webcast.mp4" />
<source src="webcast.ogv" />
<track kind="subtitles" src="./sub-en.vtt" srclang="en" />
<track kind="subtitles" src="./sub-it.vtt" srclang="it" />
</video>
<script>
$('#lang img').click(function(){
language=$(this).attr('class');
$('video track').removeAttr('default');
$('video track[srclang='+language+']').attr('default','default');
});
</script>
The "default" attribute is correctly inserted, but no subtitle is displaied. Manually inserting the default attribute works perfectly (on chrome and opera).
<script>
$('#lang img').click(function(){
var language=$(this).attr('class');
$($('video').prop('textTracks')).prop('mode', function(){
return this.language == language ? 'showing' : 'disabled';
});
});
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With