Skip to content

Commit

Permalink
fix: Don't gap jump at start of video if autoplay is not set (shaka-p…
Browse files Browse the repository at this point in the history
…roject#3645)

Before, the video would automatically gap jump at the start, even if the video
was not yet playing. This meant that videos with a gap at the start would jump
ahead and get rid of the video poster, even if autoplay was set to false.

Closes: shaka-project#3451
  • Loading branch information
Álvaro Velad Galván committed Oct 12, 2021
1 parent 22307d0 commit 9e15323
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/media/gap_jumping_controller.js
Expand Up @@ -154,8 +154,10 @@ shaka.media.GapJumpingController = class {
}
// Don't gap jump while paused, so that you don't constantly jump ahead
// while paused on a livestream. We make an exception for time 0, since we
// may be _required_ to seek on startup before play can begin.
if (this.video_.paused && this.video_.currentTime != 0) {
// may be _required_ to seek on startup before play can begin, but only if
// autoplay is enabled.
if (this.video_.paused && (this.video_.currentTime != 0 ||
(!this.video_.autoplay && this.video_.currentTime == 0))) {
return;
}

Expand Down
28 changes: 27 additions & 1 deletion test/media/playhead_unit.js
Expand Up @@ -1296,12 +1296,13 @@ describe('Playhead', () => {
});

// Regression test for https://github.com/google/shaka-player/issues/2987
it('does gap jump if paused at 0', () => {
it('does gap jump if paused at 0 and has autoplay', () => {
const buffered = [{start: 10, end: 20}];
video.buffered = createFakeBuffered(buffered);
video.currentTime = 0;
video.readyState = HTMLMediaElement.HAVE_ENOUGH_DATA;
video.paused = true;
video.autoplay = true;

config.jumpLargeGaps = true;
playhead = new shaka.media.MediaSourcePlayhead(
Expand All @@ -1319,6 +1320,31 @@ describe('Playhead', () => {
expect(video.currentTime).toBe(10);
});

// Regression test for https://github.com/google/shaka-player/issues/3451
it('doesn\'t gap jump if paused at 0 and hasn\'t autoplay', () => {
const buffered = [{start: 10, end: 20}];
video.buffered = createFakeBuffered(buffered);
video.currentTime = 0;
video.readyState = HTMLMediaElement.HAVE_ENOUGH_DATA;
video.paused = true;
video.autoplay = false;

config.jumpLargeGaps = true;
playhead = new shaka.media.MediaSourcePlayhead(
video,
manifest,
config,
/* startTime= */ 0,
Util.spyFunc(onSeek),
Util.spyFunc(onEvent));

playhead.notifyOfBufferingChange();
jasmine.clock().tick(500);

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

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

0 comments on commit 9e15323

Please sign in to comment.