Skip to content

Commit

Permalink
Add more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
beaufortfrancois committed Feb 7, 2023
1 parent 04cb00e commit 06fa86a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
10 changes: 10 additions & 0 deletions demo/close_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ shakaDemo.CloseButton = class extends shaka.ui.Element {
shakaDemoMain.unload();
});

if ('documentPictureInPicture' in window) {
window.documentPictureInPicture.addEventListener('enter', (event) => {
this.button_.style.display = 'none';
const pipWindow = window.documentPictureInPicture.window;
pipWindow.addEventListener('unload', (event) => {
this.button_.style.display = 'block';
});
});
}

// TODO: Make sure that the screenreader description of this control is
// localized!
}
Expand Down
3 changes: 2 additions & 1 deletion demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,8 @@ shakaDemo.Main = class {
if (document.pictureInPictureElement) {
document.exitPictureInPicture();
}
if (window.documentPictureInPicture.window) {
if (window.documentPictureInPicture &&
window.documentPictureInPicture.window) {
window.documentPictureInPicture.window.close();
}
this.player_.unload();
Expand Down
8 changes: 6 additions & 2 deletions externs/pictureinpicture.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ DocumentPictureInPicture.prototype.requestWindow = function(options) {};
DocumentPictureInPicture.prototype.window;


/** @type {?function(!Event)} */
DocumentPictureInPicture.prototype.onenter;
/**
* @param {string} type
* @param {Function} listener
*/
DocumentPictureInPicture.prototype.addEventListener =
function(type, listener) {};


/**
Expand Down
5 changes: 2 additions & 3 deletions ui/pip_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ shaka.ui.PipButton = class extends shaka.ui.Element {
const pipPlayer = this.videoContainer_;
const rectPipPlayer = pipPlayer.getBoundingClientRect();
const pipWindow = await window.documentPictureInPicture.requestWindow({
width: rectPipPlayer.width,
height: rectPipPlayer.height,
initialAspectRatio: rectPipPlayer.width / rectPipPlayer.height,
copyStyleSheets: true,
});

Expand All @@ -186,7 +185,7 @@ shaka.ui.PipButton = class extends shaka.ui.Element {

// Listen for the PiP closing event to move the player back.
pipWindow.addEventListener('unload', () => {
placeholder.replaceWith(pipPlayer);
placeholder.replaceWith(/** @type {!Node} */(pipPlayer));
}, {once: true});
}

Expand Down

0 comments on commit 06fa86a

Please sign in to comment.