Choose the language of the player in HTML5

-2

I have a video in dual audio (English and Portuguese) but when my page loads the audio is only in English.

<video width="200" height="200" controls>
  <source src="video/lucifer/T03E01.mkv" type="video/mp4">
  <source src="video/lucifer/T03E01.ogg" type="video/ogg">
  Seu navegador não suporta tags de vídeo.
</video>

I need it to play audio in Portuguese.

    
asked by anonymous 11.12.2018 / 17:25

1 answer

0

I think it's only possible to do this manipulation through JS.

<script type="text/javascript">

video = document.getElementsByTagName("video")[0];

for (i=0; i < video.audioTracks.length; i++) {
  if (video.audioTracks[i].language.substring(0,2) === "pt-BR") { /*Alterar pela lingua que você quer*/
   video.audioTracks[i].enabled = true;
  } else {
   video.audioTracks[i].enabled = false;
  }
}

</script>
    
11.12.2018 / 18:13