3691572e by Brandon Bay

Live start time tweaks & tests

Adding a test for live start position and tweaking some of the code
1 parent 8f6fac89
......@@ -141,13 +141,14 @@ videojs.Hls.prototype.handleSourceOpen = function() {
segmentDlTime = Infinity;
}
if(this.duration === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) {
var i = selectedPlaylist.segments.length - 1;
var tailDuration = 0;
while (tailDuration < 30 && i > 0) {
// start live playlists 30 seconds before the current time
if(this.duration() === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) {
var i = selectedPlaylist.segments.length - 1,
tailDuration = 0;
do {
tailDuration += selectedPlaylist.segments[i].duration;
i--;
}
} while (tailDuration < 30 && i > 0);
this.mediaIndex = i;
}
......
{
"allowCache": true,
"mediaSequence": 0,
"segments": [
{
"duration": 10,
"uri": "001.ts"
},
{
"duration": 19,
"uri": "002.ts"
},
{
"duration": 10,
"uri": "003.ts"
},
{
"duration": 11,
"uri": "004.ts"
},
{
"duration": 10,
"uri": "005.ts"
},
{
"duration": 10,
"uri": "006.ts"
},
{
"duration": 10,
"uri": "007.ts"
},
{
"duration": 10,
"uri": "008.ts"
},
{
"duration": 16,
"uri": "009.ts"
}
],
"targetDuration": 19
}
\ No newline at end of file
#EXTM3U
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:19
#EXTINF:10,0
001.ts
#EXTINF:19,0
002.ts
#EXTINF:10,0
003.ts
#EXTINF:11,0
004.ts
#EXTINF:10,0
005.ts
#EXTINF:10,0
006.ts
#EXTINF:10,0
007.ts
#EXTINF:10,0
008.ts
#EXTINF:16,0
009.ts
\ No newline at end of file
......@@ -1054,6 +1054,20 @@ test('updates the media index when a playlist reloads', function() {
strictEqual(player.hls.mediaIndex, 2, 'mediaIndex is updated after the reload');
});
test('live playlist starts 30s before live', function() {
player.src({
src: 'http://example.com/manifest/liveStart30sBefore.m3u8',
type: 'application/vnd.apple.mpegurl'
});
openMediaSource(player);
standardXHRResponse(requests[0]);
player.hls.playlists.trigger('loadedmetadata');
strictEqual(player.hls.mediaIndex, 5, 'mediaIndex is updated after the reload');
});
test('mediaIndex is zero before the first segment loads', function() {
window.manifests['first-seg-load'] =
'#EXTM3U\n' +
......