Fix video playback in StoryViewer for multiple videos
This commit is contained in:
parent
e078a2ae54
commit
a77861e5c4
3 changed files with 27 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2022 Signal Messenger, LLC
|
// Copyright 2022 Signal Messenger, LLC
|
||||||
// SPDX-License-Identifier: AGPL-3.0-only
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { Blurhash } from 'react-blurhash';
|
import { Blurhash } from 'react-blurhash';
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import { isVideoTypeSupported } from '../util/GoogleChrome';
|
||||||
export type PropsType = {
|
export type PropsType = {
|
||||||
readonly attachment?: AttachmentType;
|
readonly attachment?: AttachmentType;
|
||||||
readonly i18n: LocalizerType;
|
readonly i18n: LocalizerType;
|
||||||
|
readonly isPaused?: boolean;
|
||||||
readonly isThumbnail?: boolean;
|
readonly isThumbnail?: boolean;
|
||||||
readonly label: string;
|
readonly label: string;
|
||||||
readonly moduleClassName?: string;
|
readonly moduleClassName?: string;
|
||||||
|
@ -33,6 +34,7 @@ export type PropsType = {
|
||||||
export const StoryImage = ({
|
export const StoryImage = ({
|
||||||
attachment,
|
attachment,
|
||||||
i18n,
|
i18n,
|
||||||
|
isPaused,
|
||||||
isThumbnail,
|
isThumbnail,
|
||||||
label,
|
label,
|
||||||
moduleClassName,
|
moduleClassName,
|
||||||
|
@ -44,12 +46,26 @@ export const StoryImage = ({
|
||||||
!isDownloading(attachment) &&
|
!isDownloading(attachment) &&
|
||||||
!hasNotResolved(attachment);
|
!hasNotResolved(attachment);
|
||||||
|
|
||||||
|
const videoRef = useRef<HTMLVideoElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (shouldDownloadAttachment) {
|
if (shouldDownloadAttachment) {
|
||||||
queueStoryDownload(storyId);
|
queueStoryDownload(storyId);
|
||||||
}
|
}
|
||||||
}, [queueStoryDownload, shouldDownloadAttachment, storyId]);
|
}, [queueStoryDownload, shouldDownloadAttachment, storyId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!videoRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPaused) {
|
||||||
|
videoRef.current.pause();
|
||||||
|
} else {
|
||||||
|
videoRef.current.play();
|
||||||
|
}
|
||||||
|
}, [isPaused]);
|
||||||
|
|
||||||
if (!attachment) {
|
if (!attachment) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -85,7 +101,9 @@ export const StoryImage = ({
|
||||||
autoPlay
|
autoPlay
|
||||||
className={getClassName('__image')}
|
className={getClassName('__image')}
|
||||||
controls={false}
|
controls={false}
|
||||||
|
key={attachment.url}
|
||||||
loop={shouldLoop}
|
loop={shouldLoop}
|
||||||
|
ref={videoRef}
|
||||||
>
|
>
|
||||||
<source src={attachment.url} />
|
<source src={attachment.url} />
|
||||||
</video>
|
</video>
|
||||||
|
|
|
@ -318,6 +318,7 @@ export const StoryViewer = ({
|
||||||
<StoryImage
|
<StoryImage
|
||||||
attachment={attachment}
|
attachment={attachment}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
|
isPaused={shouldPauseViewing}
|
||||||
label={i18n('lightboxImageAlt')}
|
label={i18n('lightboxImageAlt')}
|
||||||
moduleClassName="StoryViewer__story"
|
moduleClassName="StoryViewer__story"
|
||||||
queueStoryDownload={queueStoryDownload}
|
queueStoryDownload={queueStoryDownload}
|
||||||
|
|
|
@ -7699,6 +7699,13 @@
|
||||||
"reasonCategory": "usageTrusted",
|
"reasonCategory": "usageTrusted",
|
||||||
"updated": "2021-11-30T10:15:33.662Z"
|
"updated": "2021-11-30T10:15:33.662Z"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "React-useRef",
|
||||||
|
"path": "ts/components/StoryImage.tsx",
|
||||||
|
"line": " const videoRef = useRef<HTMLVideoElement | null>(null);",
|
||||||
|
"reasonCategory": "usageTrusted",
|
||||||
|
"updated": "2022-04-29T23:54:21.656Z"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "React-useRef",
|
"rule": "React-useRef",
|
||||||
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
"path": "ts/components/StoryViewsNRepliesModal.tsx",
|
||||||
|
|
Loading…
Reference in a new issue