Skip to content

Commit 7b6bcab

Browse files
committed
fix(UI): Sync Document PiP placeholder with video poster changes (#10135)
1 parent f7458bf commit 7b6bcab

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

ui/controls.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,8 +1128,16 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
11281128
placeholder.classList.add('shaka-video-container');
11291129
placeholder.classList.add('pip-placeholder');
11301130
const video = /** @type {HTMLVideoElement} */ (this.video_);
1131-
if (video?.poster) {
1132-
const posterDiv = document.createElement('div');
1131+
let posterDiv = null;
1132+
const updatePoster = () => {
1133+
if (posterDiv) {
1134+
posterDiv.remove();
1135+
posterDiv = null;
1136+
}
1137+
if (!video?.poster) {
1138+
return;
1139+
}
1140+
posterDiv = document.createElement('div');
11331141
posterDiv.classList.add('pip-poster');
11341142
posterDiv.style.backgroundImage = `url("${video.poster}")`;
11351143
const videoWidth = video.videoWidth || video.clientWidth;
@@ -1138,9 +1146,22 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
11381146
if (videoWidth && videoHeight) {
11391147
posterDiv.style.setProperty('aspect-ratio',
11401148
`${videoWidth} / ${videoHeight}`);
1141-
placeholder.appendChild(posterDiv);
11421149
}
1150+
placeholder.prepend(posterDiv);
1151+
};
1152+
1153+
updatePoster();
1154+
1155+
const posterObserver = new MutationObserver(() => {
1156+
updatePoster();
1157+
});
1158+
if (video) {
1159+
posterObserver.observe(this.getLocalVideo(), {
1160+
attributes: true,
1161+
attributeFilter: ['poster'],
1162+
});
11431163
}
1164+
11441165
const iconWrapper = shaka.util.Dom.createHTMLElement('div');
11451166
iconWrapper.classList.add('pip-icon-wrapper');
11461167
placeholder.appendChild(iconWrapper);
@@ -1166,6 +1187,7 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
11661187

11671188
// Listen for the PiP closing event to move the player back.
11681189
this.eventManager_.listenOnce(pipWindow, 'pagehide', () => {
1190+
posterObserver.disconnect();
11691191
this.eventManager_.unlisten(pipIcon, 'click', pipAction);
11701192
pipPlayer.classList.remove('pip-mode');
11711193
placeholder.replaceWith(/** @type {!Node} */(pipPlayer));

0 commit comments

Comments
 (0)