c30dd88c by jrivera

Resolved endOfStream not being called reliably

1 parent 37b4e695
......@@ -307,40 +307,30 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() {
var
segmentInfo = this.pendingSegment_,
segment,
segments,
playlist,
currentMediaIndex,
currentBuffered,
timelineUpdates;
// stop here if the update errored or was aborted
if (!segmentInfo) {
return;
}
this.pendingSegment_ = null;
// if we've buffered to the end of the video, let the MediaSource know
currentBuffered = this.findCurrentBuffered_();
if (currentBuffered.length &&
this.duration() === currentBuffered.end(0) &&
this.mediaSource.readyState === 'open') {
this.mediaSource.endOfStream();
}
// stop here if the update errored or was aborted
if (!segmentInfo) {
return;
}
playlist = this.playlists.media();
segments = playlist.segments;
currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence);
currentBuffered = this.findCurrentBuffered_();
// if we switched renditions don't try to add segment timeline
// information to the playlist
if (segmentInfo.playlist.uri !== this.playlists.media().uri) {
return this.fillBuffer();
}
playlist = this.playlists.media();
currentMediaIndex = segmentInfo.mediaIndex + (segmentInfo.mediaSequence - playlist.mediaSequence);
// annotate the segment with any start and end time information
// added by the media processing
segment = playlist.segments[currentMediaIndex];
......@@ -350,15 +340,21 @@ videojs.Hls.prototype.setupSourceBuffer_ = function() {
timelineUpdates.forEach(function (update) {
if (segment) {
if (update.start !== undefined) {
segment.start = update.start;
}
if (update.end !== undefined) {
segment.end = update.end;
}
}
});
// if we've buffered to the end of the video, let the MediaSource know
if (this.playlists.media().endList &&
currentBuffered.length &&
segments[segments.length - 1].end <= currentBuffered.end(0) &&
this.mediaSource.readyState === 'open') {
this.mediaSource.endOfStream();
return;
}
if (timelineUpdates.length) {
this.updateDuration(playlist);
// check if it's time to download the next segment
......@@ -450,6 +446,8 @@ videojs.Hls.prototype.setCurrentTime = function(currentTime) {
return currentTime;
}
this.lastSegmentLoaded_ = null;
// cancel outstanding requests and buffer appends
this.cancelSegmentXhr();
......