Clamp seeks to the seekable range
If currentTime is called with a value outside the current seekable range, seek to the closest valid playback position instead.
Showing
2 changed files
with
43 additions
and
0 deletions
... | @@ -365,6 +365,13 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { | ... | @@ -365,6 +365,13 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { |
365 | return 0; | 365 | return 0; |
366 | } | 366 | } |
367 | 367 | ||
368 | // clamp seeks to the available seekable time range | ||
369 | if (currentTime < this.seekable().start(0)) { | ||
370 | currentTime = this.seekable().start(0); | ||
371 | } else if (currentTime > this.seekable().end(0)) { | ||
372 | currentTime = this.seekable().end(0); | ||
373 | } | ||
374 | |||
368 | // save the seek target so currentTime can report it correctly | 375 | // save the seek target so currentTime can report it correctly |
369 | // while the seek is pending | 376 | // while the seek is pending |
370 | this.lastSeekedTime_ = currentTime; | 377 | this.lastSeekedTime_ = currentTime; | ... | ... |
... | @@ -1731,6 +1731,42 @@ test('resets the time to a seekable position when resuming a live stream ' + | ... | @@ -1731,6 +1731,42 @@ test('resets the time to a seekable position when resuming a live stream ' + |
1731 | equal(seekTarget, player.seekable().end(0), 'seeked to the end of seekable'); | 1731 | equal(seekTarget, player.seekable().end(0), 'seeked to the end of seekable'); |
1732 | }); | 1732 | }); |
1733 | 1733 | ||
1734 | test('clamps seeks to the seekable window', function() { | ||
1735 | var seekTarget; | ||
1736 | player.src({ | ||
1737 | src: 'live0.m3u8', | ||
1738 | type: 'application/vnd.apple.mpegurl' | ||
1739 | }); | ||
1740 | openMediaSource(player); | ||
1741 | requests.shift().respond(200, null, | ||
1742 | '#EXTM3U\n' + | ||
1743 | '#EXT-X-MEDIA-SEQUENCE:16\n' + | ||
1744 | '#EXTINF:10,\n' + | ||
1745 | '16.ts\n'); | ||
1746 | // mock out a seekable window | ||
1747 | player.hls.seekable = function() { | ||
1748 | return { | ||
1749 | start: function() { | ||
1750 | return 160; | ||
1751 | }, | ||
1752 | end: function() { | ||
1753 | return 170; | ||
1754 | } | ||
1755 | }; | ||
1756 | }; | ||
1757 | player.hls.fillBuffer = function(time) { | ||
1758 | if (time !== undefined) { | ||
1759 | seekTarget = time; | ||
1760 | } | ||
1761 | }; | ||
1762 | |||
1763 | player.currentTime(180); | ||
1764 | equal(seekTarget * 0.001, player.seekable().end(0), 'forward seeks are clamped'); | ||
1765 | |||
1766 | player.currentTime(45); | ||
1767 | equal(seekTarget * 0.001, player.seekable().start(0), 'backward seeks are clamped'); | ||
1768 | }); | ||
1769 | |||
1734 | test('mediaIndex is zero before the first segment loads', function() { | 1770 | test('mediaIndex is zero before the first segment loads', function() { |
1735 | window.manifests['first-seg-load'] = | 1771 | window.manifests['first-seg-load'] = |
1736 | '#EXTM3U\n' + | 1772 | '#EXTM3U\n' + | ... | ... |
-
Please register or sign in to post a comment