Skip to content

Commit fccb370

Browse files
authored
Merge pull request #14228 from guardian/doml/canplaythrough
Handle Loop Video canplaythrough event
2 parents 025a8a1 + 10ab1e9 commit fccb370

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,12 @@ export const LoopVideo = ({
365365
return FallbackImageComponent;
366366
}
367367

368+
const handleCanPlay = () => {
369+
if (!isPlayable) {
370+
setIsPlayable(true);
371+
}
372+
};
373+
368374
const handlePlayPauseClick = (event: React.SyntheticEvent) => {
369375
event.preventDefault();
370376
playPauseVideo();
@@ -466,7 +472,7 @@ export const LoopVideo = ({
466472
const AudioIcon = isMuted ? SvgAudioMute : SvgAudio;
467473

468474
return (
469-
<div
475+
<figure
470476
ref={setNode}
471477
css={videoContainerStyles}
472478
className="loop-video-container"
@@ -484,9 +490,9 @@ export const LoopVideo = ({
484490
setCurrentTime={setCurrentTime}
485491
ref={vidRef}
486492
isPlayable={isPlayable}
487-
setIsPlayable={setIsPlayable}
488493
playerState={playerState}
489494
isMuted={isMuted}
495+
handleCanPlay={handleCanPlay}
490496
handlePlayPauseClick={handlePlayPauseClick}
491497
handleAudioClick={handleAudioClick}
492498
handleKeyDown={handleKeyDown}
@@ -496,6 +502,6 @@ export const LoopVideo = ({
496502
preloadPartialData={preloadPartialData}
497503
showPlayIcon={showPlayIcon}
498504
/>
499-
</div>
505+
</figure>
500506
);
501507
};

dotcom-rendering/src/components/LoopVideoPlayer.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ type Props = {
8181
height: number;
8282
FallbackImageComponent: ReactElement;
8383
isPlayable: boolean;
84-
setIsPlayable: Dispatch<SetStateAction<boolean>>;
8584
playerState: PlayerStates;
8685
currentTime: number;
8786
setCurrentTime: Dispatch<SetStateAction<number>>;
8887
isMuted: boolean;
88+
handleCanPlay: (event: SyntheticEvent) => void;
8989
handlePlayPauseClick: (event: SyntheticEvent) => void;
9090
handleAudioClick: (event: SyntheticEvent) => void;
9191
handleKeyDown: (event: React.KeyboardEvent<HTMLVideoElement>) => void;
@@ -112,11 +112,11 @@ export const LoopVideoPlayer = forwardRef(
112112
FallbackImageComponent,
113113
posterImage,
114114
isPlayable,
115-
setIsPlayable,
116115
playerState,
117116
currentTime,
118117
setCurrentTime,
119118
isMuted,
119+
handleCanPlay,
120120
handlePlayPauseClick,
121121
handleAudioClick,
122122
handleKeyDown,
@@ -149,9 +149,8 @@ export const LoopVideoPlayer = forwardRef(
149149
muted={isMuted}
150150
playsInline={true}
151151
poster={posterImage}
152-
onCanPlay={() => {
153-
setIsPlayable(true);
154-
}}
152+
onCanPlay={handleCanPlay}
153+
onCanPlayThrough={handleCanPlay}
155154
onTimeUpdate={() => {
156155
if (
157156
ref &&

0 commit comments

Comments
 (0)