Skip to content

Commit 4d17b82

Browse files
committed
fix(video): exit picture-in-picture mode on slide navigation
1 parent b7b2428 commit 4d17b82

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/plugins/video/VideoSlide.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,38 @@ export function VideoSlide({ slide, offset }: VideoSlideProps) {
113113
}
114114
}, [offset, getOwnerDocument]);
115115

116+
React.useEffect(() => {
117+
if (offset === 0) {
118+
let pip = false;
119+
120+
const trackPiP = (pipValue: boolean) => (event: Event) => {
121+
if (event.target === videoRef.current) {
122+
pip = pipValue;
123+
freezeNavigation.current = pip;
124+
}
125+
};
126+
127+
const onEnterPiP = trackPiP(true);
128+
const onLeavePiP = trackPiP(false);
129+
130+
getOwnerDocument().addEventListener("enterpictureinpicture", onEnterPiP);
131+
getOwnerDocument().addEventListener("leavepictureinpicture", onLeavePiP);
132+
133+
return () => {
134+
getOwnerDocument().removeEventListener("enterpictureinpicture", onEnterPiP);
135+
getOwnerDocument().removeEventListener("leavepictureinpicture", onLeavePiP);
136+
137+
if (pip) {
138+
freezeNavigation.current = false;
139+
140+
getOwnerDocument()
141+
.exitPictureInPicture()
142+
.catch(() => {});
143+
}
144+
};
145+
}
146+
}, [offset, getOwnerDocument]);
147+
116148
const { width, height, poster, sources } = slide;
117149

118150
const scaleWidthAndHeight = () => {

0 commit comments

Comments
 (0)