Skip to content

Commit

Permalink
Don't gap jump until seeking event fires
Browse files Browse the repository at this point in the history
This changes onPollGapJump_ to not gap jump if the video is seeking
but a seeking event has not yet occurred.
This also adds a unit test that tests for the bug in issue shaka-project#1061.

Closes shaka-project#1061

Change-Id: I8662f5878006ed8626ca8df55f0506edb2dd970e
  • Loading branch information
theodab committed Jan 5, 2018
1 parent 6bf201f commit 8ad48fa
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/media/playhead.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ shaka.media.Playhead = function(
/** @private {?shaka.util.Timer} */
this.gapJumpTimer_ = null;

/** @private {boolean} */
this.seekingEventReceived_ = false;

/**
* Used to batch up early seeks and delay until video.currentTime is updated.
*
Expand Down Expand Up @@ -422,6 +425,14 @@ shaka.media.Playhead.prototype.onSeekingToStartTime_ = function() {
shaka.media.Playhead.prototype.onPollGapJump_ = function() {
// Don't gap jump before the video is ready to play.
if (this.video_.readyState == 0) return;
// Do not gap jump if seeking has begun, but the seeking event has not
// yet fired for this particular seek.
if (this.video_.seeking) {
if (!this.seekingEventReceived_)
return;
} else {
this.seekingEventReceived_ = false;
}
// Don't gap jump while paused, so that you don't constantly jump ahead while
// paused on a livestream.
if (this.video_.paused) return;
Expand Down Expand Up @@ -563,6 +574,7 @@ shaka.media.Playhead.prototype.onSeeking_ = function() {
goog.asserts.assert(this.video_.readyState > 0,
'readyState should be greater than 0');

this.seekingEventReceived_ = true;
this.hadSegmentAppended_ = false;
var currentTime = this.video_.currentTime;
var targetTime = this.reposition_(currentTime);
Expand Down
28 changes: 28 additions & 0 deletions test/media/playhead_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,34 @@ describe('Playhead', function() {
}); // with large gaps
}); // with unbuffered seeks

it('doesn\'t gap jump if the seeking event is late', function() {
var buffered = [{start: 10, end: 20}];
video.buffered = createFakeBuffered(buffered);
video.currentTime = 12;
video.readyState = HTMLMediaElement.HAVE_ENOUGH_DATA;

config.jumpLargeGaps = true;
playhead = new shaka.media.Playhead(video, manifest, config, 12,
Util.spyFunc(onSeek),
Util.spyFunc(onEvent));

jasmine.clock().tick(1000);
expect(onEvent).not.toHaveBeenCalled();

// Append a segment before seeking.
playhead.onSegmentAppended();

// Seek backwards but wait briefly to fire the seeking event.
video.currentTime = 3;
video.readyState = HTMLMediaElement.HAVE_METADATA;
video.seeking = true;
jasmine.clock().tick(600);
video.on['seeking']();

// There should NOT have been a gap jump.
expect(video.currentTime).toBe(3);
});

/**
* @param {string} name
* @param {SeekTestInfo} data
Expand Down

0 comments on commit 8ad48fa

Please sign in to comment.