@@ -11,15 +11,15 @@ import { getZIndex } from '../lib/getZIndex';
1111import { generateImageURL } from '../lib/image' ;
1212import { useIsInView } from '../lib/useIsInView' ;
1313import { useShouldAdapt } from '../lib/useShouldAdapt' ;
14- import type { CustomPlayEventDetail } from '../lib/video' ;
14+ import type { CustomPlayEventDetail , Source } from '../lib/video' ;
1515import {
1616 customLoopPlayAudioEventName ,
1717 customYoutubePlayEventName ,
1818} from '../lib/video' ;
1919import { CardPicture , type Props as CardPictureProps } from './CardPicture' ;
2020import { useConfig } from './ConfigContext' ;
21- import type { PLAYER_STATES , PlayerStates } from './LoopVideoPlayer' ;
2221import { LoopVideoPlayer } from './LoopVideoPlayer' ;
22+ import type { PLAYER_STATES , PlayerStates } from './LoopVideoPlayer' ;
2323import { ophanTrackerWeb } from './YoutubeAtom/eventEmitters' ;
2424
2525const videoContainerStyles = css `
@@ -105,7 +105,7 @@ const doesVideoHaveAudio = (video: HTMLVideoElement): boolean => {
105105} ;
106106
107107type Props = {
108- src : string ;
108+ sources : Source [ ] ;
109109 atomId : string ;
110110 uniqueId : string ;
111111 height : number ;
@@ -120,7 +120,7 @@ type Props = {
120120} ;
121121
122122export const LoopVideo = ( {
123- src ,
123+ sources ,
124124 atomId,
125125 uniqueId,
126126 height,
@@ -164,10 +164,11 @@ export const LoopVideo = ({
164164 } ) ;
165165
166166 const playVideo = useCallback ( async ( ) => {
167- if ( ! vidRef . current ) return ;
167+ const video = vidRef . current ;
168+ if ( ! video ) return ;
168169
169170 /** https://developer.mozilla.org/en-US/docs/Web/Media/Guides/Autoplay#example_handling_play_failures */
170- const startPlayPromise = vidRef . current . play ( ) ;
171+ const startPlayPromise = video . play ( ) ;
171172
172173 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- In earlier versions of the HTML specification, play() didn't return a value
173174 if ( startPlayPromise !== undefined ) {
@@ -179,12 +180,12 @@ export const LoopVideo = ({
179180 } )
180181 . catch ( ( error : Error ) => {
181182 // Autoplay failed
182- logAndReportError ( src , error ) ;
183+ logAndReportError ( video . src , error ) ;
183184 setShowPosterImage ( true ) ;
184185 setPlayerState ( 'PAUSED_BY_BROWSER' ) ;
185186 } ) ;
186187 }
187- } , [ src ] ) ;
188+ } , [ ] ) ;
188189
189190 const pauseVideo = (
190191 reason : Extract <
@@ -529,7 +530,9 @@ export const LoopVideo = ({
529530 * Sentry and log in the console.
530531 */
531532 const onError = ( ) => {
532- const message = `Loop video could not be played. source: ${ src } ` ;
533+ const message = `Loop video could not be played. source: ${
534+ vidRef . current ?. currentSrc ?? 'unknown'
535+ } `;
533536
534537 window . guardian . modules . sentry . reportError (
535538 new Error ( message ) ,
@@ -601,7 +604,7 @@ export const LoopVideo = ({
601604 data-component = "gu-video-loop"
602605 >
603606 < LoopVideoPlayer
604- src = { src }
607+ sources = { sources }
605608 atomId = { atomId }
606609 uniqueId = { uniqueId }
607610 width = { width }
0 commit comments