Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Commit

Permalink
Fix possible seek issues in content where segment preciseDuration is …
Browse files Browse the repository at this point in the history
…shorter than playlist segment duration
  • Loading branch information
mikrohard committed Jun 18, 2015
1 parent 675d942 commit 1fcdef2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/videojs-hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ videojs.Hls.prototype.drainBuffer = function(event) {
decrypter,
segIv,
ptsTime,
tagPts,
tagIndex,
segmentOffset = 0,
segmentBuffer = this.segmentBuffer_;

Expand Down Expand Up @@ -889,14 +891,23 @@ videojs.Hls.prototype.drainBuffer = function(event) {
if (typeof offset === 'number') {
ptsTime = offset - segmentOffset + tags[0].pts;

while (tags[i].pts < ptsTime) {
tagPts = tags[i].pts;
tagIndex = i;
while (tagPts < ptsTime) {
i++;
if (tags[i] !== undefined) {
tagPts = tags[i].pts;
tagIndex = i;
}
else {
break;
}
}

// tell the SWF where we will be seeking to
this.el().vjs_setProperty('currentTime', (tags[i].pts - tags[0].pts + segmentOffset) * 0.001);
this.el().vjs_setProperty('currentTime', (tagPts - tags[0].pts + segmentOffset) * 0.001);

tags = tags.slice(i);
tags = tags.slice(tagIndex);

this.lastSeekedTime_ = null;
}
Expand Down Expand Up @@ -1125,14 +1136,15 @@ videojs.Hls.getMediaIndexByTime = function() {
* @returns {number} The current time to that point, or 0 if none appropriate.
*/
videojs.Hls.prototype.getCurrentTimeByMediaIndex_ = function(playlist, mediaIndex) {
var index, time = 0;
var index, time = 0, segment;

if (!playlist.segments || mediaIndex === 0) {
return 0;
}

for (index = 0; index < mediaIndex; index++) {
time += playlist.segments[index].duration;
segment = playlist.segments[index];
time += segment.preciseDuration || segment.duration || playlist.targetDuration || 0;
}

return time;
Expand Down

0 comments on commit 1fcdef2

Please sign in to comment.