Skip to content

Commit

Permalink
Allow seeking past the last intra frame; see phoboslab#9
Browse files Browse the repository at this point in the history
  • Loading branch information
phoboslab committed Jun 3, 2015
1 parent 8216df3 commit 2252a84
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions jsmpg.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,17 +355,15 @@ jsmpeg.prototype.collectIntraFrames = function() {
this.frameCount = frame;
};

jsmpeg.prototype.seekToFrame = function(seekFrame, seekExact) {
var target = null;
for( var i = 1; i < this.intraFrames.length; i++ ) {
if( this.intraFrames[i].frame > seekFrame ) {
target = this.intraFrames[i-1];
break;
}
jsmpeg.prototype.seekToFrame = function(seekFrame, seekExact) {
if( seekFrame < 0 || seekFrame >= this.frameCount || !this.intraFrames.length ) {
return false;
}

if( !target ) {
return false;
// Find the last intra frame before or equal to seek frame
var target = null;
for( var i = 0; i < this.intraFrames.length && this.intraFrames[i].frame <= seekFrame; i++ ) {
target = this.intraFrames[i];
}

this.buffer.index = target.index;
Expand Down

0 comments on commit 2252a84

Please sign in to comment.