Skip to content

Commit

Permalink
Added additional loadeddata event—originally defined by @OwenEdwards
Browse files Browse the repository at this point in the history
…in videojs#1949.

- Refactor `parseCue` to be managed by `loadTrack` so that `onflush` event can trigger parse complete (emulate load)
- Increased superficial load delay, to something more reliable, but it shouldn't be a problem if vtt.js is embedded in dist.
  • Loading branch information
Carey Hinoki committed Dec 7, 2015
1 parent 86b97cf commit 6986f4a
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/js/tracks/text-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ TextTrack.prototype.constructor = TextTrack;
* cuechange - One or more cues in the track have become active or stopped being active.
*/
TextTrack.prototype.allowedEvents_ = {
'cuechange': 'cuechange'
'cuechange': 'cuechange',
'loadeddata': 'loadeddata'
};

TextTrack.prototype.addCue = function(cue) {
Expand Down Expand Up @@ -233,22 +234,23 @@ TextTrack.prototype.removeCue = function(removeCue) {
* Downloading stuff happens below this point
*/
var parseCues = function(srcContent, track) {
if (typeof window['WebVTT'] !== 'function') {
//try again a bit later
return window.setTimeout(function() {
parseCues(srcContent, track);
}, 25);
}

let parser = new window['WebVTT']['Parser'](window, window['vttjs'], window['WebVTT']['StringDecoder']());

parser['oncue'] = function(cue) {
track.addCue(cue);
};

parser['onparsingerror'] = function(error) {
log.error(error);
};

parser['onflush'] = () => {
track.trigger({
type: 'loadeddata',
target: track
});
};

parser['parse'](srcContent);
parser['flush']();
};
Expand All @@ -269,7 +271,15 @@ var loadTrack = function(src, track) {
}

track.loaded_ = true;
parseCues(responseBody, track);

if (typeof window['WebVTT'] !== 'function') {
//try again a bit later
return window.setTimeout(function() {
parseCues(responseBody, track);
}, 100);
} else {
parseCues(responseBody, track);
}
}));
};

Expand Down

0 comments on commit 6986f4a

Please sign in to comment.