Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only play one video in PiP at once. #181

Merged
merged 3 commits into from
Feb 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 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,11 @@ export default class extends HTMLElement {
pipButton.disabled = true;
try {
if (this !== document.pictureInPictureElement) {
// If another video is already in PiP, pause it and exit PiP mode.
beaufortfrancois marked this conversation as resolved.
Show resolved Hide resolved
if (document.pictureInPictureElement instanceof VideoPlayer) {
document.pictureInPictureElement.videoElement.pause();
await document.exitPictureInPicture();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe await document.exitPictureInPicture(); is not necessary as document.pictureInPictureElement will exit Picture-in-Picture.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beaufortfrancois You're right, thank you. Updated in 599d9ab.

}
await this.videoElement.requestPictureInPicture();
} else {
await document.exitPictureInPicture();
Expand Down