Fix video and audio playback to pause on window close

This commit is contained in:
ayumi-signal 2024-02-02 15:39:32 -08:00 committed by GitHub
parent d215e1b9be
commit 96131112da
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 98 additions and 1 deletions

View file

@ -36,6 +36,7 @@ export type PropsType = {
i18n: LocalizerType;
isViewOnce?: boolean;
media: ReadonlyArray<ReadonlyDeep<MediaItemType>>;
playbackDisabled: boolean;
saveAttachment: SaveAttachmentActionCreatorType;
selectedIndex: number;
toggleForwardMessagesModal: (messageIds: ReadonlyArray<string>) => unknown;
@ -82,6 +83,7 @@ export function Lightbox({
saveAttachment,
selectedIndex,
toggleForwardMessagesModal,
playbackDisabled,
onMediaPlaybackStart,
onNextAttachment,
onPrevAttachment,
@ -250,6 +252,16 @@ export function Lightbox({
}
}, [videoElement, onMediaPlaybackStart]);
useEffect(() => {
if (!videoElement || videoElement.paused) {
return;
}
if (playbackDisabled) {
videoElement.pause();
}
}, [playbackDisabled, videoElement]);
useEffect(() => {
const div = document.createElement('div');
document.body.appendChild(div);