Skip to content

Commit c232867

Browse files
authored
feat(ABR): Use PiP window size when using documentPictureInPicture (#7880)
Close #7872
1 parent bc6a79f commit c232867

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

lib/abr/simple_abr_manager.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ shaka.abr.SimpleAbrManager = class {
107107

108108
/** @private {shaka.util.Timer} */
109109
this.resizeObserverTimer_ = new shaka.util.Timer(() => {
110-
if (this.enabled_ && this.config_.restrictToElementSize) {
110+
if (this.enabled_ && (this.config_.restrictToElementSize ||
111+
this.config_.restrictToScreenSize)) {
111112
const chosenVariant = this.chooseVariant();
112113
if (chosenVariant) {
113114
this.switch_(chosenVariant, this.config_.clearBufferSwitch,
@@ -116,6 +117,26 @@ shaka.abr.SimpleAbrManager = class {
116117
}
117118
});
118119

120+
/** @private {Window} */
121+
this.windowToCheck_ = window;
122+
123+
if ('documentPictureInPicture' in window) {
124+
this.eventManager_.listen(
125+
window.documentPictureInPicture, 'enter', () => {
126+
this.windowToCheck_ = window.documentPictureInPicture.window;
127+
if (this.resizeObserverTimer_) {
128+
this.resizeObserverTimer_.tickNow();
129+
}
130+
this.eventManager_.listenOnce(
131+
this.windowToCheck_, 'pagehide', () => {
132+
this.windowToCheck_ = window;
133+
if (this.resizeObserverTimer_) {
134+
this.resizeObserverTimer_.tickNow();
135+
}
136+
});
137+
});
138+
}
139+
119140
/** @private {?shaka.util.CmsdManager} */
120141
this.cmsdManager_ = null;
121142
}
@@ -176,15 +197,15 @@ shaka.abr.SimpleAbrManager = class {
176197
let maxWidth = Infinity;
177198

178199
if (this.config_.restrictToScreenSize) {
179-
const devicePixelRatio =
180-
this.config_.ignoreDevicePixelRatio ? 1 : window.devicePixelRatio;
181-
maxHeight = window.screen.height * devicePixelRatio;
182-
maxWidth = window.screen.width * devicePixelRatio;
200+
const devicePixelRatio = this.config_.ignoreDevicePixelRatio ?
201+
1 : this.windowToCheck_.devicePixelRatio;
202+
maxHeight = this.windowToCheck_.screen.height * devicePixelRatio;
203+
maxWidth = this.windowToCheck_.screen.width * devicePixelRatio;
183204
}
184205

185206
if (this.resizeObserver_ && this.config_.restrictToElementSize) {
186-
const devicePixelRatio =
187-
this.config_.ignoreDevicePixelRatio ? 1 : window.devicePixelRatio;
207+
const devicePixelRatio = this.config_.ignoreDevicePixelRatio ?
208+
1 : this.windowToCheck_.devicePixelRatio;
188209
maxHeight = Math.min(
189210
maxHeight, this.mediaElement_.clientHeight * devicePixelRatio);
190211
maxWidth = Math.min(

0 commit comments

Comments
 (0)