diff options
author | Sam Potts <sam@selz.com> | 2016-02-21 11:28:15 +1100 |
---|---|---|
committer | Sam Potts <sam@selz.com> | 2016-02-21 11:28:15 +1100 |
commit | 6a0b3dc823f48294b967f9123294d3e2068e3a8f (patch) | |
tree | 0a9ae7a4e033e00d071e8b88879f3ab92238aed4 /src | |
parent | 32b7b6b88692a5fc3dd4443ae6f442fc400fdf92 (diff) | |
parent | 402c45ee2bf1d528ea1c3ea333dfa7fcb7dd79af (diff) | |
download | plyr-6a0b3dc823f48294b967f9123294d3e2068e3a8f.tar.lz plyr-6a0b3dc823f48294b967f9123294d3e2068e3a8f.tar.xz plyr-6a0b3dc823f48294b967f9123294d3e2068e3a8f.zip |
Merge pull request #168 from gurupras/fix-captions
Fixes for captions
Diffstat (limited to 'src')
-rw-r--r-- | src/js/plyr.js | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/js/plyr.js b/src/js/plyr.js index fce746db..b2b9c964 100644 --- a/src/js/plyr.js +++ b/src/js/plyr.js @@ -820,15 +820,21 @@ } // Utilities for caption time codes - function _timecodeMin(tc) { + function _timecodeCommon(tc, pos) { var tcpair = []; tcpair = tc.split(' --> '); - return _subTcSecs(tcpair[0]); + for(var i = 0; i < tcpair.length; i++) { + // WebVTT allows for extra meta data after the timestamp line + // So get rid of this if it exists + tcpair[i] = tcpair[i].replace(/(\d+:\d+:\d+\.\d+).*/, "$1"); + } + return _subTcSecs(tcpair[pos]); + } + function _timecodeMin(tc) { + return _timecodeCommon(tc, 0); } function _timecodeMax(tc) { - var tcpair = []; - tcpair = tc.split(' --> '); - return _subTcSecs(tcpair[1]); + return _timecodeCommon(tc, 1); } function _subTcSecs(tc) { if (tc === null || tc === undefined) { @@ -1517,12 +1523,18 @@ record, req = xhr.responseText; - records = req.split('\n\n'); - + var pattern = '\n'; + records = req.split(pattern + pattern); + if(records.length === 1) { + // The '\n' pattern didn't work + // Try '\r\n' + pattern = '\r\n'; + records = req.split(pattern + pattern); + } for (var r = 0; r < records.length; r++) { record = records[r]; plyr.captions[r] = []; - plyr.captions[r] = record.split('\n'); + plyr.captions[r] = record.split(pattern); } // Remove first element ('VTT') |