0

I'm trying to implement a way to navigate through the subtitles of a video that has subtitles in WebVTT format.

Task:
I would like to click on a button to make the video go to the beginning of the previous cue, but sometimes the video is between two cues, so when evaluating texttrack.activeCues the result is an empty element.

Problem:
I can think of several ways to do this, but none of them seem the most efficient or logical. Let's say the video is currently at minute 100, where there is no active cue, how do I know what the previous cue is when I don't have a reference id?

I don't know if there is some element inside the TextTrackCueList that will help me without having to make an algorithm that goes through all the cues and evaluate them. There should be a simpler way I think. I appreciate any help you can give me.

VC.One
  • 14,790
  • 4
  • 25
  • 57
  • _"How do I know what the previous cue is when I don't have a reference id?"_ Maybe create a `var last_cueTime = 0;` then use the [cuechange event](https://developer.mozilla.org/en-US/docs/Web/API/TextTrack/cuechange_event) to update the variable with video's **currentTime**. This way `last_cueTime ` has the most recent timestamp for a previous cue and you can just seek to that time on your button. – VC.One Nov 04 '21 at 13:42
  • Thank you very much for your feedback. The problem with this, is that I have a progress bar where you can click on to go to any part of the video, so when you click on it you will lose the count. What I did so far is calculating an estimate of the cue from the currentTime, and from there I go back or forward one by one until I get the current cue. Not sure if this is efficient but works. – Rodrigo Yanez Nov 04 '21 at 22:19

0 Answers0