From 4d9931712e018d739123401b53f233ab5be467ce Mon Sep 17 00:00:00 2001 From: amtins Date: Sat, 13 May 2023 20:57:34 +0200 Subject: [PATCH] fix(player): load method fails to reset the media element to its initial state when the VHS is used --- src/js/player.js | 8 ++++++++ test/unit/player.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/js/player.js b/src/js/player.js index 7d42ddd224..707010a98b 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -3534,6 +3534,14 @@ class Player extends Component { * Begin loading the src data. */ load() { + // Workaround to use the load method with the VHS. + // Does not cover the case when the load method is called directly from the mediaElement. + if (this.tech_.vhs) { + this.src(this.currentSource()); + + return; + } + this.techCall_('load'); } diff --git a/test/unit/player.test.js b/test/unit/player.test.js index 9831b0090d..0d8df17f34 100644 --- a/test/unit/player.test.js +++ b/test/unit/player.test.js @@ -3230,3 +3230,31 @@ QUnit.test('turning on audioPosterMode when audioOnlyMode is already on will tur assert.notOk(player.audioOnlyMode(), 'audioOnlyMode is false'); }); }); + +QUnit.test('player#load resets the media element to its initial state', function(assert) { + const player = TestHelpers.makePlayer({}); + + player.src({ src: 'http://vjs.zencdn.net/v/oceans2.mp4', type: 'video/mp4' }); + + // Declaring spies here avoids spying on previous calls + const techGet_ = sinon.spy(player, 'techCall_'); + const src = sinon.spy(player, 'src'); + + player.load(); + + // Case when the VHS tech is not used + assert.ok(techGet_.calledOnce, 'techCall_ was called once'); + assert.ok(src.notCalled, 'src was not called'); + + // Simulate the VHS tech + player.tech_.vhs = true; + player.load(); + + // Case when the VHS tech is used + assert.ok(techGet_.calledOnce, 'techCall_ remains the same'); + assert.ok(src.calledOnce, 'src was called'); + + techGet_.restore(); + src.restore(); + player.dispose(); +});