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() { ...@@ -143,10 +143,10 @@ videojs.Hls.prototype.handleSourceOpen = function() {
143 143
144 // start live playlists 30 seconds before the current time 144 // start live playlists 30 seconds before the current time
145 if (this.duration() === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) { 145 if (this.duration() === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) {
146 tailIterator = selectedPlaylist.segments.length - 1; 146 tailIterator = selectedPlaylist.segments.length;
147 tailDuration = 0; 147 tailDuration = 0;
148 while (tailDuration < 30 && tailIterator > 0) { 148 while (tailDuration < 30 && tailIterator > 0) {
149 tailDuration += selectedPlaylist.segments[tailIterator].duration; 149 tailDuration += selectedPlaylist.segments[tailIterator - 1].duration;
150 tailIterator--; 150 tailIterator--;
151 } 151 }
152 this.mediaIndex = tailIterator; 152 this.mediaIndex = tailIterator;
......
...@@ -1065,7 +1065,7 @@ test('live playlist starts 30s before live', function() { ...@@ -1065,7 +1065,7 @@ test('live playlist starts 30s before live', function() {
1065 1065
1066 player.hls.playlists.trigger('loadedmetadata'); 1066 player.hls.playlists.trigger('loadedmetadata');
1067 1067
1068 strictEqual(player.hls.mediaIndex, 5, 'mediaIndex is updated after the reload'); 1068 strictEqual(player.hls.mediaIndex, 6, 'mediaIndex is updated after the reload');
1069 }); 1069 });
1070 1070
1071 test('mediaIndex is zero before the first segment loads', function() { 1071 test('mediaIndex is zero before the first segment loads', function() {
......