Skip to content

Commit

Permalink
fix(UI): Disable PiP on casting (#6110)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad committed Jan 16, 2024
1 parent de7d8d3 commit 6312fa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
3 changes: 3 additions & 0 deletions ui/controls.js
Expand Up @@ -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_);
Expand Down
26 changes: 5 additions & 21 deletions ui/pip_button.js
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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.
Expand All @@ -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()) {
Expand Down

0 comments on commit 6312fa3

Please sign in to comment.