Skip to content

Commit

Permalink
fix(player): cache_.currentTime is not updated when the current time …
Browse files Browse the repository at this point in the history
…is set

Updating cache_.currentTime as soon as the currentTime is set avoids having to wait for the timeupdate event, which results in:

- making cache_.currentTime more reliable
- updating the progress bar on mouse up after dragging when the media is paused.

See also: videojs#6232, videojs#6234, videojs#6370, videojs#6372
  • Loading branch information
amtins committed May 20, 2023
1 parent d9884c1 commit 7fa7336
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,10 @@ class Player extends Component {

this.techCall_('setCurrentTime', seconds);
this.cache_.initTime = 0;

if (isFinite(seconds)) {
this.cache_.currentTime = Number(seconds);
}
}

/**
Expand Down
14 changes: 14 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2676,6 +2676,20 @@ QUnit.test('Should accept multiple calls to currentTime after player initializat
assert.equal(player.currentTime(), 800, 'The last value passed is stored as the currentTime value');
});

QUnit.test('Should be able to set the cache currentTime after player initialization as soon the canplay event is fired', function(assert) {
const player = TestHelpers.makePlayer({});

player.src('xyz.mp4');
player.currentTime(500);

assert.strictEqual(player.getCache().currentTime, 0, 'cache currentTime value was not changed');

this.clock.tick(100);
player.trigger('canplay');

assert.strictEqual(player.getCache().currentTime, 500, 'cache currentTime value is the one passed after initialization');
});

QUnit.test('Should fire debugon event when debug mode is enabled', function(assert) {
const player = TestHelpers.makePlayer({});
const debugOnSpy = sinon.spy();
Expand Down

0 comments on commit 7fa7336

Please sign in to comment.