fix(UI): Fix auto-load with source tags (#7430)

In 4425dca2, we broke auto-loading content with `<source>` tags or
`src=` in the UI, such that we tried to load content before we had
attached a video element. That was almost a year ago. Oops!

This also adds an appropriate unit test.
This commit is contained in:
Joey Parrish
2024-10-18 01:00:15 -07:00
committed by GitHub
parent 2d14dd5480
commit 0f2ee89df9
2 changed files with 55 additions and 2 deletions
+53
View File
@@ -70,6 +70,59 @@ describe('UI', () => {
});
});
describe('set up with one container and src=', () => {
/** @type {!HTMLElement} */
let container;
/** @type {!HTMLVideoElement} */
let video;
beforeEach(async () => {
container =
/** @type {!HTMLElement} */ (document.createElement('div'));
document.body.appendChild(container);
video = shaka.test.UiUtils.createVideoElement();
video.src = 'test:sintel_multi_lingual_multi_res';
container.appendChild(video);
await UiUtils.createUIThroughDOMAutoSetup(
[container], [video]);
});
it('has loaded the video', () => {
expect(video.duration).not.toBeNaN();
expect(video.duration).not.toBe(0);
});
});
describe('set up with one container and source element', () => {
/** @type {!HTMLElement} */
let container;
/** @type {!HTMLVideoElement} */
let video;
beforeEach(async () => {
container =
/** @type {!HTMLElement} */ (document.createElement('div'));
document.body.appendChild(container);
video = shaka.test.UiUtils.createVideoElement();
container.appendChild(video);
const sourceElement = shaka.util.Dom.createSourceElement(
'test:sintel_multi_lingual_multi_res');
video.appendChild(sourceElement);
await UiUtils.createUIThroughDOMAutoSetup(
[container], [video]);
});
it('has loaded the video', () => {
expect(video.duration).not.toBeNaN();
expect(video.duration).not.toBe(0);
});
});
describe('set up with several containers', () => {
/** @type {!HTMLElement} */
let container1;
+2 -2
View File
@@ -497,6 +497,8 @@ shaka.ui.Overlay = class {
video.removeChild(source);
}
await player.attach(shaka.util.Dom.asHTMLMediaElement(video));
for (const url of urls) {
try { // eslint-disable-next-line no-await-in-loop
await ui.getControls().getPlayer().load(url);
@@ -505,8 +507,6 @@ shaka.ui.Overlay = class {
shaka.log.error('Error auto-loading asset', e);
}
}
await player.attach(shaka.util.Dom.asHTMLMediaElement(video));
}