c1f9ab02 by Brandon Bay

Correcting live first segment

Start time was going back one segment too far due to an array indexing
error
1 parent cbf5bc25
......@@ -143,10 +143,10 @@ videojs.Hls.prototype.handleSourceOpen = function() {
// start live playlists 30 seconds before the current time
if (this.duration() === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) {
tailIterator = selectedPlaylist.segments.length - 1;
tailIterator = selectedPlaylist.segments.length;
tailDuration = 0;
while (tailDuration < 30 && tailIterator > 0) {
tailDuration += selectedPlaylist.segments[tailIterator].duration;
tailDuration += selectedPlaylist.segments[tailIterator - 1].duration;
tailIterator--;
}
this.mediaIndex = tailIterator;
......
......@@ -1065,7 +1065,7 @@ test('live playlist starts 30s before live', function() {
player.hls.playlists.trigger('loadedmetadata');
strictEqual(player.hls.mediaIndex, 5, 'mediaIndex is updated after the reload');
strictEqual(player.hls.mediaIndex, 6, 'mediaIndex is updated after the reload');
});
test('mediaIndex is zero before the first segment loads', function() {
......