Skip to content

Commit

Permalink
Fixed issues around webvtt cue time parsing. Fixed #877, fixed #183.. c…
Browse files Browse the repository at this point in the history
…loses #1236
  • Loading branch information
trmb authored and heff committed Jun 13, 2014
1 parent 91aa06f commit bb50466
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
## HEAD (Unreleased)
* Added cross-browser isArray for cross-frame support. fixes #1195 ([view](https://github.com/videojs/video.js/pull/1218))
* Fixed support for webvtt chapters. Fixes #676. ([view](https://github.com/videojs/video.js/pull/1221))
* Fixed issues around webvtt cue time parsing. Fixed #877, fixed #183. ([view](https://github.com/videojs/video.js/pull/1236))

--------------------

Expand Down
4 changes: 2 additions & 2 deletions src/js/tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,9 @@ vjs.TextTrack.prototype.parseCues = function(srcContent) {
};

// Timing line
time = line.split(' --> ');
time = line.split(/[\t ]+/);
cue.startTime = this.parseCueTime(time[0]);
cue.endTime = this.parseCueTime(time[1]);
cue.endTime = this.parseCueTime(time[2]);

// Additional lines - Cue Text
text = [];
Expand Down
21 changes: 11 additions & 10 deletions test/unit/tracks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ test('cue time parsing', function() {
equal(parse('11:11'), 671, 'Only minutes and seconds (11:11)');
equal(parse('11:11:11'), 40271, 'Hours, minutes, seconds (11:11:11)');
equal(parse('11:11:11.111'), 40271.111, 'Hours, minutes, seconds, decimals (11:11:11.111)');

// Uncommment to test a fix for #877
// equal(parse('11:11 line:90%'), 671, 'minutes, seconds with flags');
// equal(parse('11:11:11 line:90%'), 40271, 'hours, minutes, seconds with flags');
});

test('cue parsing', function() {
Expand All @@ -43,10 +39,15 @@ test('cue parsing', function() {
equal(mockTrack.cues_[0].endTime, 4.11, 'Cue end time w/ spaces');
equal(mockTrack.cues_[0].text, 'Text line 1', 'Cue text');

// Uncomment to test a fix for #183
// mockTrack.reset(); // reset mock track
// var timeWithTabs = vttHead + '00:00.700\t-->\t00:04.110\nText line 1';
// mockTrack.parseCues(timeWithTabs);
// equal(mockTrack.cues_[0].startTime, 0.7, 'Cue start time w/ spaces');
// equal(mockTrack.cues_[0].endTime, 4.11, 'Cue end time w/ spaces');
mockTrack.reset(); // reset mock track
var timeWithTabs = vttHead + '00:00.700\t-->\t00:04.110\nText line 1';
mockTrack.parseCues(timeWithTabs);
equal(mockTrack.cues_[0].startTime, 0.7, 'Cue start time w/ spaces');
equal(mockTrack.cues_[0].endTime, 4.11, 'Cue end time w/ spaces');

mockTrack.reset(); // reset mock track
var timeWithMixedWhiteSpace = vttHead + '00:00.700 -->\t 00:04.110\nText line 1';
mockTrack.parseCues(timeWithMixedWhiteSpace);
equal(mockTrack.cues_[0].startTime, 0.7, 'Cue start time w/ spaces');
equal(mockTrack.cues_[0].endTime, 4.11, 'Cue end time w/ spaces');
});

0 comments on commit bb50466

Please sign in to comment.