language property

Gets the BCP47 language tag of an AudioTrack or TextTrack if available, or an empty string if not.

This property is read-only.

HTML5 A vocabulary and associated APIs for HTML and XHTMLInternet Explorer 10

 

Syntax

JavaScript
language = object.language

 

Property values

Type: string

The BCP47 language tag of the track. For example "en" for English or "fr" for French.

Standards information

Remarks

The language tag is not displayed to the user for text tracks. The following example uses the label attribute for text to display (such as "English") in the player's track list.


    <video id="video1" controls autoplay loop>
      <source src="http://ie.microsoft.com/testdrive/ieblog/2011/nov/pp4_blog_demo.mp4" type="video/mp4" >
      <track id="enTrack" src="entrack.vtt" label="English" kind="subtitles" srclang="en" default> 
      <track id="esTrack" src="estrack.vtt" label="Spanish" kind="subtitles" srclang="es">
      <track id="deTrack" src="detrack.vtt" label="German" kind="subtitles" srclang="de">
      HTML5 video not supported
    </video>


The audio track label is set when the video is created, or you can use the label property to set it.

Examples

The following example gets the number of audioTracks associated with a video object, and displays the language and enabled status of each.


<!DOCTYPE html >
<html >
  <head>
  <title>AudioTracks example</title>

  </head>
  <body>
    <h1>AudioTrack languages example</h1>
    <video id="video1" src="multi-lang-movie.mp4" controls >HTML5 video not supported </video>
    <br />
    <button id="mybutton">Get language status</button>
    <div id="display"></div>
  
    <script>
      document.getElementById("mybutton").addEventListener("click", function () {
        var oAudioTracks = document.getElementById("video1").audioTracks;
        var display = document.getElementById("display");
        display.innerHTML = "";
        for (var i = 0; i < oAudioTracks.length; i++) {
          display.innerHTML += "Track " + i;
          display.innerHTML += " Language: " + oAudioTracks[i].language;
          display.innerHTML += " is   " + ((oAudioTracks[i].enabled == true) ? "enabled" : "not enabled") + "<br/>";
        }
      },false);    
  </script>
  </body>
</html>


See also

AudioTrack
TextTrack

 

 

Show:
© 2014 Microsoft