Skip to content

Commit

Permalink
Merge pull request #181 from GoogleChrome/fix/ghost-pip-bug
Browse files Browse the repository at this point in the history
Only play one video in PiP at once.
  • Loading branch information
derekherman authored Feb 1, 2022
2 parents cf09a7e + ff908c3 commit 14d0740
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/web-components/video-player/VideoPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
PIP_CLASSNAME,
} from '../../constants';

export default class extends HTMLElement {
export default class VideoPlayer extends HTMLElement {
/**
* @param {VideoDownloader} downloader Video downloader associated with the current video.
*/
Expand Down Expand Up @@ -464,6 +464,10 @@ export default class extends HTMLElement {
pipButton.disabled = true;
try {
if (this !== document.pictureInPictureElement) {
// If another video is already in PiP, pause it.
if (document.pictureInPictureElement instanceof VideoPlayer) {
document.pictureInPictureElement.videoElement.pause();
}
await this.videoElement.requestPictureInPicture();
} else {
await document.exitPictureInPicture();
Expand Down

0 comments on commit 14d0740

Please # to comment.