@@ -58,7 +58,7 @@ export const LoopVideo = ({
58
58
if ( ! vidRef . current ) return ;
59
59
60
60
if ( isInView ) {
61
- // We only want to autoplay the first time the video comes into view.
61
+ // We only autoplay the first time the video comes into view.
62
62
if ( hasBeenInView ) return ;
63
63
64
64
if ( window . matchMedia ( '(prefers-reduced-motion: reduce)' ) . matches ) {
@@ -82,19 +82,31 @@ export const LoopVideo = ({
82
82
83
83
if ( adapted ) return fallbackImageComponent ;
84
84
85
- const handleClick = ( event : React . SyntheticEvent ) => {
86
- event . preventDefault ( ) ;
85
+ const playVideo = ( ) => {
86
+ if ( ! vidRef . current ) return ;
87
+ setIsPlaying ( true ) ;
88
+ void vidRef . current . play ( ) ;
89
+ } ;
90
+
91
+ const pauseVideo = ( ) => {
87
92
if ( ! vidRef . current ) return ;
93
+ setIsPlaying ( false ) ;
94
+ void vidRef . current . pause ( ) ;
95
+ } ;
88
96
97
+ const playPauseVideo = ( ) => {
89
98
if ( isPlaying ) {
90
- setIsPlaying ( false ) ;
91
- void vidRef . current . pause ( ) ;
99
+ pauseVideo ( ) ;
92
100
} else {
93
- setIsPlaying ( true ) ;
94
- void vidRef . current . play ( ) ;
101
+ playVideo ( ) ;
95
102
}
96
103
} ;
97
104
105
+ const handleClick = ( event : React . SyntheticEvent ) => {
106
+ event . preventDefault ( ) ;
107
+ playPauseVideo ( ) ;
108
+ } ;
109
+
98
110
const onError = ( ) => {
99
111
window . guardian . modules . sentry . reportError (
100
112
new Error ( `Loop video could not be played. source: ${ src } ` ) ,
@@ -134,14 +146,20 @@ export const LoopVideo = ({
134
146
switch ( event . key ) {
135
147
case 'Enter' :
136
148
case ' ' :
137
- handleClick ( event ) ;
149
+ playPauseVideo ( ) ;
150
+ break ;
151
+ case 'Escape' :
152
+ pauseVideo ( ) ;
138
153
break ;
139
154
case 'ArrowRight' :
140
155
seekForward ( ) ;
141
156
break ;
142
157
case 'ArrowLeft' :
143
158
seekBackward ( ) ;
144
159
break ;
160
+ case 'm' :
161
+ setIsMuted ( ! isMuted ) ;
162
+ break ;
145
163
}
146
164
} ;
147
165
0 commit comments