Skip to content

Commit 6312fa3

Browse files
authored
fix(UI): Disable PiP on casting (#6110)
1 parent de7d8d3 commit 6312fa3

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

ui/controls.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget {
650650
* @export
651651
*/
652652
isPiPAllowed() {
653+
if (this.castProxy_.isCasting()) {
654+
return false;
655+
}
653656
if ('documentPictureInPicture' in window &&
654657
this.config_.preferDocumentPictureInPicture) {
655658
const video = /** @type {HTMLVideoElement} */(this.localVideo_);

ui/pip_button.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
9898
this.onLeavePictureInPicture_();
9999
});
100100

101-
this.eventManager.listen(this.controls, 'caststatuschanged', (e) => {
102-
this.onCastStatusChange_(e);
101+
this.eventManager.listen(this.controls, 'caststatuschanged', () => {
102+
this.onTracksChanged_();
103103
});
104104

105105
this.eventManager.listen(this.player, 'trackschanged', () => {
@@ -164,25 +164,6 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
164164
this.localization.resolve(currentPipState);
165165
}
166166

167-
/**
168-
* @param {Event} e
169-
* @private
170-
*/
171-
onCastStatusChange_(e) {
172-
const isCasting = e['newStatus'];
173-
174-
if (isCasting) {
175-
// Picture-in-picture is not applicable if we're casting
176-
if (this.controls.isPiPAllowed()) {
177-
shaka.ui.Utils.setDisplay(this.pipButton_, false);
178-
}
179-
} else {
180-
if (this.controls.isPiPAllowed()) {
181-
shaka.ui.Utils.setDisplay(this.pipButton_, true);
182-
}
183-
}
184-
}
185-
186167

187168
/**
188169
* Display the picture-in-picture button only when the content contains video.
@@ -194,6 +175,9 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
194175
async onTracksChanged_() {
195176
if (!this.controls.isPiPAllowed()) {
196177
shaka.ui.Utils.setDisplay(this.pipButton_, false);
178+
if (this.controls.isPiPEnabled()) {
179+
await this.controls.togglePiP();
180+
}
197181
} else if (this.player && this.player.isAudioOnly()) {
198182
shaka.ui.Utils.setDisplay(this.pipButton_, false);
199183
if (this.controls.isPiPEnabled()) {

0 commit comments

Comments
 (0)