getMediaIndexByTime was returning -1 at playlist boundaries
It should correctly return the first or last segment in the playlist.
Showing
2 changed files
with
26 additions
and
0 deletions
... | @@ -1115,6 +1115,10 @@ videojs.Hls.translateMediaIndex = function(mediaIndex, original, update) { | ... | @@ -1115,6 +1115,10 @@ videojs.Hls.translateMediaIndex = function(mediaIndex, original, update) { |
1115 | videojs.Hls.getMediaIndexByTime = function(playlist, time) { | 1115 | videojs.Hls.getMediaIndexByTime = function(playlist, time) { |
1116 | var index, counter, timeRanges, currentSegmentRange; | 1116 | var index, counter, timeRanges, currentSegmentRange; |
1117 | 1117 | ||
1118 | if (time === 0) { | ||
1119 | return 0; | ||
1120 | } | ||
1121 | |||
1118 | timeRanges = []; | 1122 | timeRanges = []; |
1119 | for (index = 0; index < playlist.segments.length; index++) { | 1123 | for (index = 0; index < playlist.segments.length; index++) { |
1120 | currentSegmentRange = {}; | 1124 | currentSegmentRange = {}; |
... | @@ -1123,6 +1127,10 @@ videojs.Hls.getMediaIndexByTime = function(playlist, time) { | ... | @@ -1123,6 +1127,10 @@ videojs.Hls.getMediaIndexByTime = function(playlist, time) { |
1123 | timeRanges.push(currentSegmentRange); | 1127 | timeRanges.push(currentSegmentRange); |
1124 | } | 1128 | } |
1125 | 1129 | ||
1130 | if (time >= timeRanges[timeRanges.length - 1].end) { | ||
1131 | return (playlist.segments.length - 1); | ||
1132 | } | ||
1133 | |||
1126 | for (counter = 0; counter < timeRanges.length; counter++) { | 1134 | for (counter = 0; counter < timeRanges.length; counter++) { |
1127 | if (time >= timeRanges[counter].start && time < timeRanges[counter].end) { | 1135 | if (time >= timeRanges[counter].start && time < timeRanges[counter].end) { |
1128 | return counter; | 1136 | return counter; | ... | ... |
... | @@ -1728,6 +1728,24 @@ test('mediaIndex is zero before the first segment loads', function() { | ... | @@ -1728,6 +1728,24 @@ test('mediaIndex is zero before the first segment loads', function() { |
1728 | strictEqual(player.hls.mediaIndex, 0, 'mediaIndex is zero'); | 1728 | strictEqual(player.hls.mediaIndex, 0, 'mediaIndex is zero'); |
1729 | }); | 1729 | }); |
1730 | 1730 | ||
1731 | test('mediaIndex returns correctly at playlist boundaries', function() { | ||
1732 | player.src({ | ||
1733 | src: 'http://example.com/master.m3u8', | ||
1734 | type: 'application/vnd.apple.mpegurl' | ||
1735 | }); | ||
1736 | |||
1737 | openMediaSource(player); | ||
1738 | standardXHRResponse(requests.shift()); // master | ||
1739 | standardXHRResponse(requests.shift()); // media | ||
1740 | |||
1741 | strictEqual(player.hls.mediaIndex, 0, 'mediaIndex is zero at first segment'); | ||
1742 | |||
1743 | // seek to end | ||
1744 | player.currentTime(40); | ||
1745 | |||
1746 | strictEqual(player.hls.mediaIndex, 3, 'mediaIndex is 3 at last segment'); | ||
1747 | }); | ||
1748 | |||
1731 | test('reloads out-of-date live playlists when switching variants', function() { | 1749 | test('reloads out-of-date live playlists when switching variants', function() { |
1732 | player.src({ | 1750 | player.src({ |
1733 | src: 'http://example.com/master.m3u8', | 1751 | src: 'http://example.com/master.m3u8', | ... | ... |
-
Please register or sign in to post a comment