9ec4a560 by Brandon Bay

Using segment length (not average) to snap to live

Counts segments using their individual duration to look back 30s from
live to set video start position
1 parent 873a2dd7
...@@ -141,11 +141,14 @@ videojs.Hls.prototype.handleSourceOpen = function() { ...@@ -141,11 +141,14 @@ videojs.Hls.prototype.handleSourceOpen = function() {
141 segmentDlTime = Infinity; 141 segmentDlTime = Infinity;
142 } 142 }
143 143
144 if(this.duration() === Infinity) { 144 if(this.duration() === Infinity && this.mediaIndex === 0) {
145 var lookback = Math.round(30 / segmentDuration); 145 var i = selectedPlaylist.segments.length - 1;
146 if (selectedPlaylist.segments.length > lookback) { 146 var tailDuration = 0;
147 this.mediaIndex = selectedPlaylist.segments.length - lookback; 147 while (tailDuration < 30 && i > 0) {
148 tailDuration += selectedPlaylist.segments[i].duration;
149 i--;
148 } 150 }
151 this.mediaIndex = i;
149 } 152 }
150 153
151 // this threshold is to account for having a high latency on the manifest 154 // this threshold is to account for having a high latency on the manifest
......