Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(player): load method fails to reset the media element #8274

Merged
merged 2 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
28 changes: 28 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});