f564cde0 by Tom Johnson

fix broken seek implementation

1 parent fa0dd47c
...@@ -80,7 +80,6 @@ var ...@@ -80,7 +80,6 @@ var
80 mediaSource = new videojs.MediaSource(), 80 mediaSource = new videojs.MediaSource(),
81 segmentParser = new videojs.hls.SegmentParser(), 81 segmentParser = new videojs.hls.SegmentParser(),
82 player = this, 82 player = this,
83 tech,
84 extname, 83 extname,
85 srcUrl, 84 srcUrl,
86 85
...@@ -111,20 +110,22 @@ var ...@@ -111,20 +110,22 @@ var
111 }; 110 };
112 111
113 player.on('seeking', function() { 112 player.on('seeking', function() {
114 var seekValue = tech.vjs_getProperty('lastSeekedTime'); 113 var seekValue = player.el().querySelector('.vjs-tech').vjs_getProperty('lastSeekedTime');
115 player.hls.mediaIndex = player.hls.getSegmentIndexByTime(seekValue); 114 player.hls.mediaIndex = player.hls.getSegmentIndexByTime(seekValue);
115 console.log('seek to ', seekValue, 'segment index', player.hls.mediaIndex);
116 fillBuffer(seekValue * 1000); 116 fillBuffer(seekValue * 1000);
117 }); 117 });
118 118
119 player.on('waiting', function() { 119 player.on('timeupdate', function() {
120 if (player.hls.mediaIndex === player.hls.media.segments.length) { 120 console.log('tu', player.currentTime());
121 player.pause();
122 player.trigger('ended');
123 }
124 }); 121 });
125 122
126 player.hls.getSegmentByTime = function(time) { 123 player.on('ended', function() {
127 var index, currentSegment; 124 console.log('ended');
125 })
126
127 player.hls.getSegmentIndexByTime = function(time) {
128 var index, counter, timeRanges, currentSegmentRange;
128 129
129 if (player.hls.media && player.hls.media.segments) { 130 if (player.hls.media && player.hls.media.segments) {
130 131
...@@ -248,7 +249,7 @@ var ...@@ -248,7 +249,7 @@ var
248 // update the duration 249 // update the duration
249 player.duration(parser.manifest.totalDuration); 250 player.duration(parser.manifest.totalDuration);
250 // Notify the flash layer 251 // Notify the flash layer
251 player.el().getElementsByClassName('vjs-tech')[0].vjs_setProperty('duration',parser.manifest.totalDuration); 252 player.el().querySelector('.vjs-tech').vjs_setProperty('duration',parser.manifest.totalDuration);
252 } 253 }
253 player.trigger('loadedmanifest'); 254 player.trigger('loadedmanifest');
254 player.trigger('loadedmetadata'); 255 player.trigger('loadedmetadata');
...@@ -324,17 +325,28 @@ var ...@@ -324,17 +325,28 @@ var
324 // transmux the segment data from MP2T to FLV 325 // transmux the segment data from MP2T to FLV
325 segmentParser.parseSegmentBinaryData(new Uint8Array(segmentXhr.response)); 326 segmentParser.parseSegmentBinaryData(new Uint8Array(segmentXhr.response));
326 327
327 // handle intra-segment seeking, if requested 328 console.log('reporting segment', player.hls.mediaIndex, player.hls.media.segments.length);
328 if (millisecond !== undefined) { 329
329 for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) { 330 if(player.hls.mediaIndex === player.hls.media.segments.length-1)
331 {
332 console.log('- tag count', segmentParser.getTags().length);
333 console.log('- start pts', segmentParser.getTags()[0].pts);
334 console.log('- end pts', segmentParser.getTags()[segmentParser.getTags().length-1].pts);
335 player.duration(19);
336 }
337
338 // handle intra-segment seeking, if requested //
339 // do not iterate over 0 index because it comes back with the end time //
340 if (millisecond !== undefined && typeof(millisecond) === "number") {
341 for (tagIndex = 1; tagIndex < segmentParser.getTags().length; tagIndex++) {
330 if (segmentParser.getTags()[tagIndex].pts > millisecond) { 342 if (segmentParser.getTags()[tagIndex].pts > millisecond) {
331 continue; 343 break;
332 } 344 }
333 // we're seeking past this tag, so ignore it 345 // we're seeking past this tag, so ignore it
334 segmentParser.getNextTag(); 346 segmentParser.getNextTag();
335 } 347 }
336 348 player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', segmentParser.getTags()[tagIndex].pts/1000);
337 tech.vjs_setProperty('lastSeekedTime', segmentParser.getTags()[tagIndex].pts / 1000); 349 console.log('LST', tagIndex, '/', segmentParser.getTags().length, segmentParser.getTags()[tagIndex].pts/1000, player.currentTime());
338 } 350 }
339 351
340 while (segmentParser.tagsAvailable()) { 352 while (segmentParser.tagsAvailable()) {
......