Skip to content

Commit 702589c

Browse files
committed
Poster image must be provided
1 parent bd35469 commit 702589c

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

dotcom-rendering/src/components/LoopVideo.importable.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ type Props = {
2020
videoId: string;
2121
width?: number;
2222
height?: number;
23+
posterImage: string;
24+
fallbackImageComponent: JSX.Element;
2325
hasAudio?: boolean;
24-
fallbackImage: JSX.Element;
25-
posterImage?: string;
2626
};
2727

2828
export const LoopVideo = ({
2929
src,
3030
videoId,
3131
width = 600,
3232
height = 360,
33-
hasAudio = true,
34-
fallbackImage,
3533
posterImage,
34+
fallbackImageComponent,
35+
hasAudio = true,
3636
}: Props) => {
3737
const adapted = useShouldAdapt();
3838
const { renderingTarget } = useConfig();
@@ -60,18 +60,17 @@ export const LoopVideo = ({
6060
if (!vidRef.current) return;
6161

6262
if (isInView) {
63-
if (!hasBeenInView) {
64-
if (
65-
window.matchMedia('(prefers-reduced-motion: reduce)')
66-
.matches
67-
) {
68-
setPrefersReducedMotion(true);
69-
return;
70-
}
71-
// When the video first comes into view, it should autoplay
72-
setIsPlaying(true);
73-
void vidRef.current.play();
63+
// We only want to autoplay the first time the video comes into view.
64+
if (hasBeenInView) return;
65+
66+
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
67+
setPrefersReducedMotion(true);
68+
return;
7469
}
70+
71+
setIsPlaying(true);
72+
void vidRef.current.play();
73+
7574
setHasBeenInView(true);
7675
}
7776

@@ -83,7 +82,7 @@ export const LoopVideo = ({
8382

8483
if (renderingTarget !== 'Web') return null;
8584

86-
if (adapted) return fallbackImage;
85+
if (adapted) return fallbackImageComponent;
8786

8887
const handleClick = (event: React.SyntheticEvent) => {
8988
event.preventDefault();
@@ -162,7 +161,7 @@ export const LoopVideo = ({
162161
width={width}
163162
height={height}
164163
hasAudio={hasAudio}
165-
fallbackImage={fallbackImage}
164+
fallbackImageComponent={fallbackImageComponent}
166165
currentTime={currentTime}
167166
setCurrentTime={setCurrentTime}
168167
ref={vidRef}

dotcom-rendering/src/components/LoopVideo.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const Default = {
2525
width: 600,
2626
posterImage:
2727
'https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg',
28-
fallbackImage: (
28+
fallbackImageComponent: (
2929
<CardPicture
3030
mainImage="https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg"
3131
imageSize="large"

dotcom-rendering/src/components/LoopVideoPlayer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type Props = {
4242
width: number;
4343
height: number;
4444
hasAudio: boolean;
45-
fallbackImage: JSX.Element;
45+
fallbackImageComponent: JSX.Element;
4646
isPlayable: boolean;
4747
setIsPlayable: Dispatch<SetStateAction<boolean>>;
4848
isPlaying: boolean;
@@ -56,8 +56,8 @@ type Props = {
5656
onError: (event: SyntheticEvent<HTMLVideoElement>) => void;
5757
AudioIcon: (iconProps: IconProps) => JSX.Element;
5858
/**
59-
* We show a poster image when the user has indicated that
60-
* they do not want videos to play automatically
59+
* We show a poster image when the user has indicated that they do
60+
* not want videos to play automatically, e.g. prefers reduced motion.
6161
*/
6262
posterImage?: string;
6363
};
@@ -74,7 +74,7 @@ export const LoopVideoPlayer = forwardRef(
7474
width,
7575
height,
7676
hasAudio,
77-
fallbackImage,
77+
fallbackImageComponent,
7878
posterImage,
7979
isPlayable,
8080
setIsPlayable,
@@ -133,7 +133,7 @@ export const LoopVideoPlayer = forwardRef(
133133
performance on supported browsers. https://web.dev/articles/video-and-source-tags */}
134134
{/* <source src={webmSrc} type="video/webm"> */}
135135
<source src={src} type="video/mp4" />
136-
{fallbackImage}
136+
{fallbackImageComponent}
137137
</video>
138138
{ref && 'current' in ref && ref.current && (
139139
<>

0 commit comments

Comments
 (0)