Choose the language of the player in HTML5

Asked

Viewed 633 times

-1

I have a dual audio video (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 him to play the audio in Portuguese.

1 answer

0

I believe that it is only possible to make 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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.