From 7fa73365dea748c5030c500e23f5e283f0e9c460 Mon Sep 17 00:00:00 2001 From: amtins Date: Sat, 20 May 2023 17:16:26 +0200 Subject: [PATCH] fix(player): cache_.currentTime is not updated when the current time 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: #6232, #6234, #6370, #6372 --- src/js/player.js | 4 ++++ test/unit/player.test.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/js/player.js b/src/js/player.js index d98ee70680..6927f1723e 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -2485,6 +2485,10 @@ class Player extends Component { this.techCall_('setCurrentTime', seconds); this.cache_.initTime = 0; + + if (isFinite(seconds)) { + this.cache_.currentTime = Number(seconds); + } } /** diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 9831b0090d..24830bb818 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -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();