w3c / picture-in-picture

Picture-in-Picture (PiP)
https://w3c.github.io/picture-in-picture
Other
309 stars 38 forks source link

No way to access PictureInPictureWindow when initiated by the user agent. #79

Closed jeremysjones closed 6 years ago

jeremysjones commented 6 years ago

When the user agent initiates picture in picture there is no way for the page to get access to the PictureInPictureWindow.

Normally the page would gain access to the PictureInPictureWindow when calling requestPictureInPicture().

Mobile Safari initiates picture-in-picture when app is suspended while playing fullscreen video or the user can press the picture-in-picture button on the video fullscreen window. In these cases, the page will still need access to the PictureInPictureWindow in order to respond to window size changes.

Proposed solutions: Add a pictureInPictureWindow property to the element or document.

beaufortfrancois commented 6 years ago

Thanks @jeremysjones for raising this issue.

Instead of adding a pictureInPictureWindow property to the HTMLVideoElement or document, how about adding it as part of the enterpictureinpicture event.

[ 
 Constructor(DOMString type, EnterPictureInPictureEventInit eventInitDict)
]
interface EnterPictureInPictureEvent : Event {
    attribute PictureInPictureWindow pictureInPictureWindow;
};

This would allow web developers to do something like this:

video.addEventListener('enterpictureinpicture', function(event) {
  const pipWindow = event.pictureInPictureWindow;
  // TODO: Update video size based on `pipWindow.width` and `pipWindow.height`;
});
mounirlamouri commented 6 years ago

@jeremysjones WDYT of @beaufortfrancois proposal? I think it's cleaner and would avoid footguns with some components of the page reading the state of the PIP window and changing behaviour when it's actually the PIP window of another video.

jeremysjones commented 6 years ago

@mounirlamouri @beaufortfrancois I agree. Adding it to the event is an even better solution.

beaufortfrancois commented 6 years ago

FYI I've just opened a PR to add pictureInPictureWindow to the enterpictureinpicture event at https://github.com/WICG/picture-in-picture/pull/84