11import { css } from '@emotion/react' ;
2- import { log } from '@guardian/libs' ;
2+ import { log , storage } from '@guardian/libs' ;
33import { SvgAudio , SvgAudioMute } from '@guardian/source/react-components' ;
44import { useEffect , useRef , useState } from 'react' ;
55import { getZIndex } from '../lib/getZIndex' ;
@@ -80,8 +80,8 @@ export const LoopVideo = ({
8080 /**
8181 * Setup.
8282 *
83- * Register the users motion preferences.
84- * Creates event listeners to control playback when there are multiple videos.
83+ * 1. Register the user's motion preferences.
84+ * 2. Creates event listeners to control playback when there are multiple videos.
8585 */
8686 useEffect ( ( ) => {
8787 /**
@@ -90,7 +90,19 @@ export const LoopVideo = ({
9090 const userPrefersReducedMotion = window . matchMedia (
9191 '(prefers-reduced-motion: reduce)' ,
9292 ) . matches ;
93- setIsAutoplayAllowed ( ! userPrefersReducedMotion ) ;
93+
94+ /**
95+ * The user indicates a preference for no flashing elements.
96+ * `flashingPreference` is `null` if no preference exists and
97+ * explicitly `false` when the reader has said they don't want flashing.
98+ */
99+ const flashingPreferences = storage . local . get (
100+ 'gu.prefs.accessibility.flashing-elements' ,
101+ ) ;
102+
103+ setIsAutoplayAllowed (
104+ ! userPrefersReducedMotion && flashingPreferences !== false ,
105+ ) ;
94106
95107 /**
96108 * Mutes the current video when another video is unmuted
@@ -110,7 +122,7 @@ export const LoopVideo = ({
110122 } ;
111123
112124 /**
113- * Mute the current video when a Youtube video is played
125+ * Mute the current video when a YouTube video is played
114126 * Triggered by the CustomEvent in YoutubeAtomPlayer.
115127 */
116128 const handleCustomPlayYoutubeEvent = ( ) => {
@@ -190,7 +202,7 @@ export const LoopVideo = ({
190202
191203 void vidRef . current . play ( ) ;
192204 }
193- } , [ isInView , hasBeenInView , playerState ] ) ;
205+ } , [ isInView , hasBeenInView , playerState , isAutoplayAllowed ] ) ;
194206
195207 /**
196208 * Show the play icon when the video is not playing, except for when it is scrolled
0 commit comments