Reputation: 159
I want a way to check whether or not a video is in picture in picture mode after someone has entered in picture in picture mode. They may close the video in PIP mode by clicking the X button,I want to check the state of the video with a recursive function and see when they close it, and change the class of some element. something like this
if(video.isInPipMode){
someRecursiveFunction();
}
is there anyway , any property to check the state of a video and see whether or not it is still in PIP mode, thanks in advance/
Upvotes: 1
Views: 2026
Reputation: 20954
You can either check the document for the pictureInPictureElement
to see if there is a current video in PiP mode. It either returns the element that is currently in PiP mode or null
when there is not.
if (document.pictureInPictureElement !== null) {
someRecursiveFunction();
}
Or attach events to the video to listen for when a video enters or leaves the PiP mode.
let pipActive = false;
video.addEventListener('enterpictureinpicture', () => {
pipActive = true;
});
video.addEventListener('leavepictureinpicture', () => {
pipActive = false;
});
Upvotes: 3