How to select audio tracks in different languages (Windows Store apps using JavaScript and HTML)

1 out of 1 rated this helpful - Rate this topic

You can use the audioTracks property to switch between multiple audio tracks on a media file. For example, media files could contain multiple audio tracks in different languages. The audioTracks attribute is available on the Video and Audio elements.

You can search the list of audio tracks by iterating through the audioTracks property. When you find the desired track, select it by setting the enabled property to true. If the enabled track is changed, be sure to set the enabled property on the previous track to false.

The language of the track is represented by using a language code.

This example iterates through the audio tracks on a Video object and compares the language property to "en-gb". When the desired track is found, the enabled property is set to true.


function selectLang() {
    var myVideo = document.getElementById("videoTag1");
    
    if (myVideo.audioTracks.length > 1) {
        for (var i = 0; i < myVideo.audioTracks.length ; i++) {
            if (myVideo.audioTracks[i].language == "en-gb") {
                myVideo.audioTracks[i].enabled = true;
            }
            else {
                myVideo.audioTracks[i].enabled = false;
            }
        }
    }

    myVideo.play();
}


Related topics

Video
Audio
Media Playback Sample

 

 

Build date: 11/29/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.