Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reading all the cues from a caption #1966

Closed
acv opened this issue Mar 23, 2015 · 8 comments
Closed

Reading all the cues from a caption #1966

acv opened this issue Mar 23, 2015 · 8 comments
Milestone

Comments

@acv
Copy link

acv commented Mar 23, 2015

I'm trying to port https://github.com/walsh9/videojs-transcript to 4.12 from 4.9 and obviously, the changes in tracks have been challenging. I think I have it pretty much taken care of except for this bit that completely stumps me:

    if (track.readyState() !==2) {
      track.load();
      track.on('loaded', createTranscript);
    } else {
      createTranscript();
    }

I can't find readyState anywhere either as a property or method. Nor can I figure out the track.load() replacement. And while I can use addEventListener() for the event handler, loaded never fires, nor does load or, well, anything else I can find.

Without those checks, cues is empty by them time createTranscript() is called and so I can't build a transcript from the captions.

Javascript is far from my first (or fifth) language so I can't figure out how to get there from the new code.

@gkatsev gkatsev added this to the Text Tracks milestone Mar 23, 2015
@gkatsev
Copy link
Member

gkatsev commented Mar 23, 2015

We need to write documentation for the new captions. Sorry we haven't done it yet.
As for getting all the cues, tracks have a cues property that gives you all the cues for the track. Each cue has a text property with the text of the cue.
A track has been loaded once the cues property is accessible.

Meanwhile, you can find some links to the text track spec (which is what our API is based on) in this issue: #1655

I'm going to close this, but please post more related questions here if you have it.

@gkatsev gkatsev closed this as completed Mar 23, 2015
@acv
Copy link
Author

acv commented Mar 23, 2015

At the time the plugin runs, textTracks()[0].cues is empty. Once I click the close captioning button in the UI and then break out the Javascript debugger, cues contain 7 items (in my test), my question is how do I make sure that cues is non-empty.

@gkatsev
Copy link
Member

gkatsev commented Mar 23, 2015

Yeah, there's currently no event for that currently from the native side, but if you're using the <track> elements, you can listen to it's load event. Otherwise, at the video's loadmetadata, the tracks are probably going to be fetched by then.
The issue is also whether you're dealing with native tracks or emulated tracks. Emulated tracks happen when we're using a flash tech or when the browser doesn't support tracks enough for what we need them for.
There's more discussion about the load event for emulated tracks in #1949

@acv
Copy link
Author

acv commented Mar 23, 2015

This worked:

      if (!track.cues) {
          window.setTimeout(function() { createTranscript(); }, 100);
      } else {
          createTranscript();
      }

I'm using <track> tags with a vtt caption and Chrome Version 41.0.2272.101 (64-bit) on MacOS X

@gkatsev
Copy link
Member

gkatsev commented Mar 23, 2015

@OwenEdwards
Copy link
Member

@acv, you and I have done something very similar: https://github.com/OwenEdwards/videojs-transcript. I'd love to get the tests passing too, if you have any thoughts?

@gkatsev, this was one of the reasons I'd proposed the 'loadeddata' patch for tracks in #1949, but you're right, there needs to be a cleaner, more standards-compliant solution.

@acv
Copy link
Author

acv commented Mar 23, 2015

I'm very new to HTML5 (or javascript newer then Netscape 4) the spec seems to imply that readyState belongs to the track element and that the track element will fire a load event when loaded. How to get the track element from the TextTrack and whether that actually works, dunno.

@OwenEdwards
Copy link
Member

As @gkatsev mentions on #1949, the TextTrack doesn't have a track element, although it can be created by a track element (or by addRemoteTextTrack). Then there's the issue of whether the tech is doing native track support, or VideoJS is doing emulated tracks.

I think your solution (with the setTimeout) is the best one right now; I'd add a reference to #1949, so you can look at it again, once that issue is resolved.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants