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() { ...@@ -141,13 +141,14 @@ videojs.Hls.prototype.handleSourceOpen = function() {
141 segmentDlTime = Infinity; 141 segmentDlTime = Infinity;
142 } 142 }
143 143
144 if(this.duration === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) { 144 // start live playlists 30 seconds before the current time
145 var i = selectedPlaylist.segments.length - 1; 145 if(this.duration() === Infinity && this.mediaIndex === 0 && selectedPlaylist.segments) {
146 var tailDuration = 0; 146 var i = selectedPlaylist.segments.length - 1,
147 while (tailDuration < 30 && i > 0) { 147 tailDuration = 0;
148 do {
148 tailDuration += selectedPlaylist.segments[i].duration; 149 tailDuration += selectedPlaylist.segments[i].duration;
149 i--; 150 i--;
150 } 151 } while (tailDuration < 30 && i > 0);
151 this.mediaIndex = i; 152 this.mediaIndex = i;
152 } 153 }
153 154
......
1 {
2 "allowCache": true,
3 "mediaSequence": 0,
4 "segments": [
5 {
6 "duration": 10,
7 "uri": "001.ts"
8 },
9 {
10 "duration": 19,
11 "uri": "002.ts"
12 },
13 {
14 "duration": 10,
15 "uri": "003.ts"
16 },
17 {
18 "duration": 11,
19 "uri": "004.ts"
20 },
21 {
22 "duration": 10,
23 "uri": "005.ts"
24 },
25 {
26 "duration": 10,
27 "uri": "006.ts"
28 },
29 {
30 "duration": 10,
31 "uri": "007.ts"
32 },
33 {
34 "duration": 10,
35 "uri": "008.ts"
36 },
37 {
38 "duration": 16,
39 "uri": "009.ts"
40 }
41 ],
42 "targetDuration": 19
43 }
...\ No newline at end of file ...\ No newline at end of file
1 #EXTM3U
2 #EXT-X-MEDIA-SEQUENCE:0
3 #EXT-X-ALLOW-CACHE:YES
4 #EXT-X-TARGETDURATION:19
5 #EXTINF:10,0
6 001.ts
7 #EXTINF:19,0
8 002.ts
9 #EXTINF:10,0
10 003.ts
11 #EXTINF:11,0
12 004.ts
13 #EXTINF:10,0
14 005.ts
15 #EXTINF:10,0
16 006.ts
17 #EXTINF:10,0
18 007.ts
19 #EXTINF:10,0
20 008.ts
21 #EXTINF:16,0
22 009.ts
...\ No newline at end of file ...\ No newline at end of file
...@@ -1054,6 +1054,20 @@ test('updates the media index when a playlist reloads', function() { ...@@ -1054,6 +1054,20 @@ test('updates the media index when a playlist reloads', function() {
1054 strictEqual(player.hls.mediaIndex, 2, 'mediaIndex is updated after the reload'); 1054 strictEqual(player.hls.mediaIndex, 2, 'mediaIndex is updated after the reload');
1055 }); 1055 });
1056 1056
1057 test('live playlist starts 30s before live', function() {
1058 player.src({
1059 src: 'http://example.com/manifest/liveStart30sBefore.m3u8',
1060 type: 'application/vnd.apple.mpegurl'
1061 });
1062 openMediaSource(player);
1063
1064 standardXHRResponse(requests[0]);
1065
1066 player.hls.playlists.trigger('loadedmetadata');
1067
1068 strictEqual(player.hls.mediaIndex, 5, 'mediaIndex is updated after the reload');
1069 });
1070
1057 test('mediaIndex is zero before the first segment loads', function() { 1071 test('mediaIndex is zero before the first segment loads', function() {
1058 window.manifests['first-seg-load'] = 1072 window.manifests['first-seg-load'] =
1059 '#EXTM3U\n' + 1073 '#EXTM3U\n' +
......