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

How to determine type of leaving picture in picture mode ? #228

Open
kmsheng opened this issue Jul 5, 2024 · 15 comments
Open

How to determine type of leaving picture in picture mode ? #228

kmsheng opened this issue Jul 5, 2024 · 15 comments

Comments

@kmsheng
Copy link

kmsheng commented Jul 5, 2024

CleanShot 2024-07-05 at 16 49 42@2x

Is there any way to determine what button was triggered in leavepictureinpicture event ?

@beaufortfrancois
Copy link
Collaborator

It's not possible as far as I know. Out of curiosity, what is your case?

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

@beaufortfrancois I have a streamer page that has a video element, once I open the picture-in-picture window and switch to other page. I need to go back to the streamer page by clicking the Back to tab button.

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

There's a workaround to solve this issue, but it fails for the paused video.

@beaufortfrancois
Copy link
Collaborator

Sorry, it's not clear to me what's the use case yet.
If there were a reason string in onleavepictureinpicture for instance, what would it allow you to do?

video.onleavepictureinpicture = (event) => {
  if (event.reason == "backToTab") {
    // What would you differently?
  } else {
    // Do what you do.
  }
};

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

@beaufortfrancois Hey, appreciate your response. Then it would allow me to go back to the original streamer page by clicking the “Back to tab” button of pip video. It’s not really a full page redirect, it’s a frontend route change triggered by vue router. ( I hide my video element in other page, but it’s still on DOM tree )

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

@beaufortfrancois I don’t know if my use case is common or not, most of the demos I see online that “back to tab” usually happens on the same page.

@beaufortfrancois
Copy link
Collaborator

I wonder if using the Page Visibility API would be enough in your use case to know when the tab is visible again. What do you think?

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

Probably not, because it’s on the same tab.

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

YouTube has a similar approach, but it’s done with a regular fixed position DOM element ( not using pip api )

@beaufortfrancois
Copy link
Collaborator

You may want to use the Document Picture-in-Picture API. Look at https://developer.chrome.com/docs/web-platform/document-picture-in-picture/

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

Yes, documentPictureInPicture is a desirable solution if it has a better browser support rate.

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

I've created a simple demo video to illustrate the use case.
https://www.youtube.com/watch?v=bNuw1CpZSKY

@kmsheng
Copy link
Author

kmsheng commented Jul 5, 2024

In above video, when I click the close button, I want to stay in the about page.
Currently there's no way to distinguish between close btn and back to tab button.
Reason string would be a good fit in this example.

@beaufortfrancois
Copy link
Collaborator

We'll monitor how many people will vote for this issue then and we'll see if adding a reason string should be added to the onleavepictureinpicture event listener.

@kmsheng
Copy link
Author

kmsheng commented Jul 9, 2024

Sure, thank you for your support : )

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

No branches or pull requests

2 participants