Skip to content

Commit

Permalink
add player methods and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-barstow committed Oct 8, 2024
1 parent d58c166 commit 3b7d199
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,36 @@ class Player extends Component {
return false;
}

/**
* Add a <source> element to the <video> element.
*
* @param {string} srcUrl
* The URL of the video source.
*
* @param {string} [mimeType]
* The MIME type of the video source. Optional but recommended.
*/
addSourceElement(srcUrl, mimeType) {
if (this.tech_) {
this.tech_.addSourceElement(srcUrl, mimeType);
}
}

/**
* Remove a <source> element from the <video> element by its URL.
*
* @param {string} srcUrl
* The URL of the source to remove.
*
* @return {boolean}
* Returns true if the source element was successfully removed, false otherwise.
*/
removeSourceElement(srcUrl) {
if (this.tech_) {
return this.tech_.removeSourceElement(srcUrl);
}
}

/**
* Begin loading the src data.
*/
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 @@ -3611,3 +3611,31 @@ QUnit.test('smooth seeking set to true should update the display time components
player.dispose();
});

QUnit.test('addSourceElement calls tech method with correct args', function(assert) {
const player = TestHelpers.makePlayer();
const addSourceElementSpy = sinon.spy(player.tech_, 'addSourceElement');
const srcUrl = 'http://example.com/video.mp4';
const mimeType = 'video/mp4';

player.addSourceElement(srcUrl, mimeType);

assert.ok(addSourceElementSpy.calledOnce, 'addSourceElement method called');
assert.ok(addSourceElementSpy.calledWith(srcUrl, mimeType), 'addSourceElement called with correct arguments');

addSourceElementSpy.restore();
player.dispose();
});

QUnit.test('removeSourceElement calls tech method with correct args', function(assert) {
const player = TestHelpers.makePlayer();
const removeSourceElementSpy = sinon.spy(player.tech_, 'removeSourceElement');
const srcUrl = 'http://example.com/video.mp4';

player.removeSourceElement(srcUrl);

assert.ok(removeSourceElementSpy.calledOnce, 'removeSourceElement method called');
assert.ok(removeSourceElementSpy.calledWith(srcUrl), 'removeSourceElement called with correct arguments');

removeSourceElementSpy.restore();
player.dispose();
});
2 changes: 2 additions & 0 deletions test/unit/tech/tech-faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class TechFaker extends Tech {
}
return 'movie.mp4';
}
addSourceElement() {}
removeSourceElement() {}
load() {
}
currentSrc() {
Expand Down

0 comments on commit 3b7d199

Please sign in to comment.