Skip to content

Commit 35fad1d

Browse files
authored
fix(player): load method fails to reset the media element to its initial state when the VHS is used (#8274)
1 parent 665154f commit 35fad1d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/js/player.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,14 @@ class Player extends Component {
35333533
* Begin loading the src data.
35343534
*/
35353535
load() {
3536+
// Workaround to use the load method with the VHS.
3537+
// Does not cover the case when the load method is called directly from the mediaElement.
3538+
if (this.tech_.vhs) {
3539+
this.src(this.currentSource());
3540+
3541+
return;
3542+
}
3543+
35363544
this.techCall_('load');
35373545
}
35383546

test/unit/player.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3231,6 +3231,34 @@ QUnit.test('turning on audioPosterMode when audioOnlyMode is already on will tur
32313231
});
32323232
});
32333233

3234+
QUnit.test('player#load resets the media element to its initial state', function(assert) {
3235+
const player = TestHelpers.makePlayer({});
3236+
3237+
player.src({ src: 'http://vjs.zencdn.net/v/oceans2.mp4', type: 'video/mp4' });
3238+
3239+
// Declaring spies here avoids spying on previous calls
3240+
const techGet_ = sinon.spy(player, 'techCall_');
3241+
const src = sinon.spy(player, 'src');
3242+
3243+
player.load();
3244+
3245+
// Case when the VHS tech is not used
3246+
assert.ok(techGet_.calledOnce, 'techCall_ was called once');
3247+
assert.ok(src.notCalled, 'src was not called');
3248+
3249+
// Simulate the VHS tech
3250+
player.tech_.vhs = true;
3251+
player.load();
3252+
3253+
// Case when the VHS tech is used
3254+
assert.ok(techGet_.calledOnce, 'techCall_ remains the same');
3255+
assert.ok(src.calledOnce, 'src was called');
3256+
3257+
techGet_.restore();
3258+
src.restore();
3259+
player.dispose();
3260+
});
3261+
32343262
QUnit.test('crossOrigin value should be maintained after loadMedia is called', function(assert) {
32353263
const fixture = document.getElementById('qunit-fixture');
32363264

0 commit comments

Comments
 (0)