f6c4316d by Jon-Carlos Rivera

Merge pull request #428 from videojs/end-of-stream

Resolved endOfStream not being called reliably
2 parents 37b4e695 c30dd88c
...@@ -307,40 +307,30 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() { ...@@ -307,40 +307,30 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() {
307 var 307 var
308 segmentInfo = this.pendingSegment_, 308 segmentInfo = this.pendingSegment_,
309 segment, 309 segment,
310 segments,
310 playlist, 311 playlist,
311 currentMediaIndex, 312 currentMediaIndex,
312 currentBuffered, 313 currentBuffered,
313 timelineUpdates; 314 timelineUpdates;
314 315
315 // stop here if the update errored or was aborted
316 if (!segmentInfo) {
317 return;
318 }
319
320 this.pendingSegment_ = null; 316 this.pendingSegment_ = null;
321 317
322 // if we've buffered to the end of the video, let the MediaSource know
323 currentBuffered = this.findCurrentBuffered_();
324 if (currentBuffered.length &&
325 this.duration() === currentBuffered.end(0) &&
326 this.mediaSource.readyState === 'open') {
327 this.mediaSource.endOfStream();
328 }
329
330 // stop here if the update errored or was aborted 318 // stop here if the update errored or was aborted
331 if (!segmentInfo) { 319 if (!segmentInfo) {
332 return; 320 return;
333 } 321 }
334 322
323 playlist = this.playlists.media();
324 segments = playlist.segments;
325 currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence);
326 currentBuffered = this.findCurrentBuffered_();
327
335 // if we switched renditions don't try to add segment timeline 328 // if we switched renditions don't try to add segment timeline
336 // information to the playlist 329 // information to the playlist
337 if (segmentInfo.playlist.uri !== this.playlists.media().uri) { 330 if (segmentInfo.playlist.uri !== this.playlists.media().uri) {
338 return this.fillBuffer(); 331 return this.fillBuffer();
339 } 332 }
340 333
341 playlist = this.playlists.media();
342 currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence);
343
344 // annotate the segment with any start and end time information 334 // annotate the segment with any start and end time information
345 // added by the media processing 335 // added by the media processing
346 segment = playlist.segments[currentMediaIndex]; 336 segment = playlist.segments[currentMediaIndex];
...@@ -350,15 +340,21 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() { ...@@ -350,15 +340,21 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() {
350 340
351 timelineUpdates.forEach(function (update) { 341 timelineUpdates.forEach(function (update) {
352 if (segment) { 342 if (segment) {
353 if (update.start !== undefined) {
354 segment.start = update.start;
355 }
356 if (update.end !== undefined) { 343 if (update.end !== undefined) {
357 segment.end = update.end; 344 segment.end = update.end;
358 } 345 }
359 } 346 }
360 }); 347 });
361 348
349 // if we've buffered to the end of the video, let the MediaSource know
350 if (this.playlists.media().endList &&
351 currentBuffered.length &&
352 segments[segments.length - 1].end <= currentBuffered.end(0) &&
353 this.mediaSource.readyState === 'open') {
354 this.mediaSource.endOfStream();
355 return;
356 }
357
362 if (timelineUpdates.length) { 358 if (timelineUpdates.length) {
363 this.updateDuration(playlist); 359 this.updateDuration(playlist);
364 // check if it's time to download the next segment 360 // check if it's time to download the next segment
...@@ -450,6 +446,8 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) { ...@@ -450,6 +446,8 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) {
450 return currentTime; 446 return currentTime;
451 } 447 }
452 448
449 this.lastSegmentLoaded_ = null;
450
453 // cancel outstanding requests and buffer appends 451 // cancel outstanding requests and buffer appends
454 this.cancelSegmentXhr(); 452 this.cancelSegmentXhr();
455 453
......