From bb50466733ab7de22e2e0463f622db91222d54b1 Mon Sep 17 00:00:00 2001 From: Troy Brandt Date: Fri, 13 Jun 2014 13:30:16 -0700 Subject: [PATCH] Fixed issues around webvtt cue time parsing. Fixed #877, fixed #183.. closes #1236 --- CHANGELOG.md | 1 + src/js/tracks.js | 4 ++-- test/unit/tracks.js | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f38ff11cf..9a6c42db1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) -------------------- diff --git a/src/js/tracks.js b/src/js/tracks.js index e753aff2e..fd0629408 100644 --- a/src/js/tracks.js +++ b/src/js/tracks.js @@ -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 = []; diff --git a/test/unit/tracks.js b/test/unit/tracks.js index 8282f7ed3..79794167e 100644 --- a/test/unit/tracks.js +++ b/test/unit/tracks.js @@ -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() { @@ -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'); });