From 171c182eed086eb32563df5c7b4667320debd4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Tue, 16 Jan 2024 18:09:38 +0100 Subject: [PATCH] fix(UI): Disable PiP on casting (#6110) --- ui/controls.js | 3 +++ ui/pip_button.js | 26 +++++--------------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/ui/controls.js b/ui/controls.js index 8465ca57c2..cab011fb84 100644 --- a/ui/controls.js +++ b/ui/controls.js @@ -650,6 +650,9 @@ shaka.ui.Controls = class extends shaka.util.FakeEventTarget { * @export */ isPiPAllowed() { + if (this.castProxy_.isCasting()) { + return false; + } if ('documentPictureInPicture' in window && this.config_.preferDocumentPictureInPicture) { const video = /** @type {HTMLVideoElement} */(this.localVideo_); diff --git a/ui/pip_button.js b/ui/pip_button.js index d95d7c2335..93bd8d28e2 100644 --- a/ui/pip_button.js +++ b/ui/pip_button.js @@ -98,8 +98,8 @@ shaka.ui.PipButton = class extends shaka.ui.Element { this.onLeavePictureInPicture_(); }); - this.eventManager.listen(this.controls, 'caststatuschanged', (e) => { - this.onCastStatusChange_(e); + this.eventManager.listen(this.controls, 'caststatuschanged', () => { + this.onTracksChanged_(); }); this.eventManager.listen(this.player, 'trackschanged', () => { @@ -164,25 +164,6 @@ shaka.ui.PipButton = class extends shaka.ui.Element { this.localization.resolve(currentPipState); } - /** - * @param {Event} e - * @private - */ - onCastStatusChange_(e) { - const isCasting = e['newStatus']; - - if (isCasting) { - // Picture-in-picture is not applicable if we're casting - if (this.controls.isPiPAllowed()) { - shaka.ui.Utils.setDisplay(this.pipButton_, false); - } - } else { - if (this.controls.isPiPAllowed()) { - shaka.ui.Utils.setDisplay(this.pipButton_, true); - } - } - } - /** * Display the picture-in-picture button only when the content contains video. @@ -194,6 +175,9 @@ shaka.ui.PipButton = class extends shaka.ui.Element { async onTracksChanged_() { if (!this.controls.isPiPAllowed()) { shaka.ui.Utils.setDisplay(this.pipButton_, false); + if (this.controls.isPiPEnabled()) { + await this.controls.togglePiP(); + } } else if (this.player && this.player.isAudioOnly()) { shaka.ui.Utils.setDisplay(this.pipButton_, false); if (this.controls.isPiPEnabled()) {