• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML Track element for video is not working.

SpongeBOB

New Coder
Hi everyone,

I have followed the guidance of this URL : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track to add a track (aka subtitle/captions) on a video.

but it's not working here the code of my page:

HTML:
<!doctype html>
<html lang="en-us">


<head>

<meta charset="utf-8">
<title>test video</title>


<body>
<video id="mylittlevdo" controls >
<source src="test.mp4" type="video/mp4"> <!-- place and rename as test.mp4 an mp4 video in the same folder -->
<track kind="subtitles" src="test.vtt" srclang="en" id="sub1" default />Your browser does not support the video tag.</video><br>

<script>
var vid = document.getElementById("mylittlevdo");

function myFunction() {
  alert(vid.textTracks[0].mode);
}
</script>

<br>
<button onclick="myFunction()" type="button">mode</button><br>

</body>
</html>

Quite simple page, so wen I click the button "mode" I see "showing" meaning that the track should appear..

The TTS file come from developer.mozilla.org... Friday.vtt

Weird as on https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track it work ! what the difference ?

Thanks.
 
Last edited:
Top