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

Picture-in-picture #171

Merged
merged 4 commits into from
Jan 14, 2022
Merged

Picture-in-picture #171

merged 4 commits into from
Jan 14, 2022

Conversation

dero
Copy link
Collaborator

@dero dero commented Dec 13, 2021

Summary

Introduces basic implementation of the programmatic picture-in-picture experience.

kino-basic-pip.mp4

To-dos

  • Figure out the UI. †

† Do we design and implement fully custom video player UI that would allow us to provide users with single controls UI and also allow us to be in control of which buttons are rendered in the UI? Or do we rather keep the PiP button as a control separate from the default video player controls?

Fixes #53

@dero dero requested a review from derekherman December 13, 2021 14:11
@dero dero self-assigned this Dec 13, 2021
@dero
Copy link
Collaborator Author

dero commented Dec 13, 2021

I've requested design help internally.

Copy link
Member

@beaufortfrancois beaufortfrancois left a comment

Choose a reason for hiding this comment

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

First draft looks good to me minus nit and UI
Thanks!

pipButton.addEventListener('click', async () => {
pipButton.disabled = true;
try {
if (this !== document.pictureInPictureElement) {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I'd use this.videoElement to be explicit as it's the <video> sub element that is in Picture-in-Picture. +1 for consistency with this.videoElement.requestPictureInPicture() ;)

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 That is not going to work, actually, as pictureInPictureElement can't refer to an element within a shadowRoot tree.

https://w3c.github.io/picture-in-picture/#documentorshadowroot-extension

The browser is supposed to run a retargeting algorithm to define a node that will be used instead. In this case it's the custom element itself.

It's an interesting caveat, I think. And it caught me by surprise, too.

Copy link
Member

Choose a reason for hiding this comment

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

My bad, you're absolutely right. I forgot about that.

@dero dero changed the title WIP: PiP Picture-in-picture Dec 30, 2021
@dero
Copy link
Collaborator Author

dero commented Dec 30, 2021

Implemented a design update:

  • Custom unified inline overlay when video is playing PiP.
  • New style for the floating button + styles that allow us to add more buttons in the future (e.g. casting).

Screencast:

kino-pip-design.mp4

@dero dero marked this pull request as ready for review December 30, 2021 12:40
Copy link
Member

@beaufortfrancois beaufortfrancois left a comment

Choose a reason for hiding this comment

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

LGTM with nit

@@ -345,6 +353,9 @@ export default class extends HTMLElement {

this.videoElement.addEventListener('loadedmetadata', setPipButton);
this.videoElement.addEventListener('emptied', setPipButton);
this.videoElement.addEventListener('enterpictureinpicture', () => this.classList.add(PIP_CLASSNAME));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: It would be great if the PiP floating button would also change shape when video is playing in 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 What do you mean by "change shape"? Like change the icon from the current "Enter PiP" icon to some kind of "Exit PiP" icon?

Copy link
Member

Choose a reason for hiding this comment

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

Yep!

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 Gotcha! Added in e484469. Here's a short screencast:

kino-exit-pip-icon.mp4

(This one's on me, our designer has originally designed both icons, but I missed it during implementation. 😐)

Copy link
Member

Choose a reason for hiding this comment

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

LGTM. Thank you @dero! See #171 (comment) as well

@dero
Copy link
Collaborator Author

dero commented Jan 4, 2022

You may want to use https://jakearchibald.github.io/svgomg/ to compress the svg html.

@beaufortfrancois I usually do that every time, but the "Enter PiP" icon seems to have slipped through. Thanks for noticing! Updated in 8e34fda.

@beaufortfrancois
Copy link
Member

This PR looks good! Thank you @dero!

@derekherman derekherman merged commit 521fe22 into develop Jan 14, 2022
@derekherman derekherman deleted the add/pip branch January 14, 2022 23:23
@felipebochehin87
Copy link

Bug related to this feature was found: #178

@felipebochehin87
Copy link

LGTM. PiP displays one video at a time, and if a second video start on PiP, the first one stops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discovery: Using Picture-in-Picture experience
4 participants