Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

HTML HTML Video and Audio (Retired) Captioning Video The Track Element

How do I add multiple tracks for subtitles in different languages?

Perhaps I want to have subtitles available in multiple languages, for example: English and Spanish. How do I make these subtitle tracks available for the User to select their preferred subtitle track?

2 Answers

This appears to be resolved once mediaelements.js is added in the subsequent Custom Media Players section.

Using the track element you can specify the language with the "srclang" (Source Language) attribute.

Example of a video with English, German, and Spanish subtitles:

<video id="video" controls preload="metadata">
   <source src="video/sintel-short.mp4" type="video/mp4">
   <source src="video/sintel-short.webm" type="video/webm">
   <track label="English" kind="subtitles" srclang="en" src="captions/vtt/sintel-en.vtt" default>
   <track label="Deutsch" kind="subtitles" srclang="de" src="captions/vtt/sintel-de.vtt">
   <track label="Español" kind="subtitles" srclang="es" src="captions/vtt/sintel-es.vtt">
</video>

I previously tried adding the multiple tracks just as you described, but I didn't see how the User is able to switch between them in the video player.

I see now that the this appears to be resolved once mediaelements.js is added in the subsequent Custom Media Players section.

Thanks for the quick reply though.

Rick