<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Working with Tracks</title>
  <script>
    function initiate() {
      let cue;
      const cues = [
        { start: 2.000, end: 7.000, text: "Welcome"},
        { start: 10.000, end: 15.000, text: "This is an example"},
        { start: 15.001, end: 20.000, text: "of how to add"},
        { start: 20.001, end: 25.000, text: "a new track."},
        { start: 27.000, end: 30.000, text: "Good bye!"},
      ];
      const video = document.getElementById("media");
      const newtrack = video.addTextTrack("subtitles");
      newtrack.mode = "showing";
      for (let f = 0; f < cues.length; f++) {
        cue = new VTTCue(cues[f].start, cues[f].end, cues[f].text);
        newtrack.addCue(cue);
      }
      video.play();
    }
    window.addEventListener("DOMContentLoaded", initiate);
  </script>
</head>
<body>
  <section>
    <video id="media" width="720" height="400" controls>
      <source src="trailer.mp4" type="video/mp4">
      <source src="trailer.webm" type="video/webm">
    </video>
  </section>
</body>
</html>