8f63b1a9 by Tom Johnson

remove time range object dependency on segments

1 parent 467fa2fe
...@@ -111,7 +111,6 @@ var ...@@ -111,7 +111,6 @@ var
111 }; 111 };
112 112
113 player.on('ready', function() { 113 player.on('ready', function() {
114 player.muted(true);
115 tech = player.el().querySelector('.vjs-tech'); 114 tech = player.el().querySelector('.vjs-tech');
116 tech.vjs_setProperty('playerId', player.P); 115 tech.vjs_setProperty('playerId', player.P);
117 }); 116 });
...@@ -122,40 +121,39 @@ var ...@@ -122,40 +121,39 @@ var
122 fillBuffer(seekValue*1000); 121 fillBuffer(seekValue*1000);
123 }); 122 });
124 123
125 player.on('waiting', function() { 124 player.on('ended', function() {
126 if(player.currentTime() >= player.duration() && player.hls.isLastSegment()) { 125 //console.log('ended received');
127 player.pause();
128 player.trigger('ended');
129 }
130 }); 126 });
131 127
132 player.hls.isLastSegment = function() { 128 player.hls.isLastSegment = function() {
133 return player.hls.mediaIndex === player.hls.selectPlaylist().segments.length; 129 return player.hls.mediaIndex === player.hls.selectPlaylist().segments.length;
134 }; 130 };
135 131
136 player.hls.getSegmentByTime = function(time) { 132 player.hls.getSegmentIndexByTime = function(time) {
137 var index, currentSegment; 133 var index, counter, currentSegmentRange, timeRanges;
138
139 if (player.hls.media && player.hls.media.segments) { 134 if (player.hls.media && player.hls.media.segments) {
135
136 timeRanges = [];
137
140 for (index = 0; index < player.hls.media.segments.length; index++) { 138 for (index = 0; index < player.hls.media.segments.length; index++) {
141 currentSegment = player.hls.media.segments[index]; 139 currentSegmentRange = {};
142 if (time > currentSegment.timeRange.start && time <= currentSegment.timeRange.end) { 140 currentSegmentRange.start = (index===0) ? 0 : timeRanges[index-1].end;
143 return currentSegment; 141 currentSegmentRange.end = currentSegmentRange.start + player.hls.media.segments[index].duration;
144 } 142 timeRanges.push(currentSegmentRange);
145 } 143 }
146 }
147 };
148 144
149 player.hls.getSegmentIndexByTime = function(time) { 145 for(counter = 0; counter < timeRanges.length; counter++){
150 var index, currentSegment; 146 if(time >= timeRanges[counter].start && time < timeRanges[counter].end) {
151 if (player.hls.media && player.hls.media.segments) { 147
152 for (index = 0; index < player.hls.media.segments.length; index++) { 148 return counter;
153 currentSegment = player.hls.media.segments[index];
154 if (time > currentSegment.timeRange.start && time <= currentSegment.timeRange.end) {
155 return index;
156 } 149 }
157 } 150 }
151
152 return null;
153
158 } 154 }
155
156 return null;
159 }; 157 };
160 158
161 /** 159 /**
...@@ -355,10 +353,18 @@ var ...@@ -355,10 +353,18 @@ var
355 targetTag = tagIndex; 353 targetTag = tagIndex;
356 } 354 }
357 } 355 }
356
357 try {
358 tech.vjs_setProperty('lastSeekedTime', segmentParser.getTags()[targetTag].pts/1000);
359 } catch(err) {
360
361 }
362
358 while(bleedIndex < targetTag) { 363 while(bleedIndex < targetTag) {
359 segmentParser.getNextTag(); 364 segmentParser.getNextTag();
360 bleedIndex++; 365 bleedIndex++;
361 } 366 }
367
362 } 368 }
363 369
364 while (segmentParser.tagsAvailable()) { 370 while (segmentParser.tagsAvailable()) {
......