From e5a6cf365ed6f2cc58ee57e5e4ee06823a6c0ff1 Mon Sep 17 00:00:00 2001 From: Tom <20648924+moT01@users.noreply.github.com> Date: Tue, 7 May 2024 14:17:02 -0500 Subject: [PATCH] fix: english audio again (#54696) --- .../Challenges/components/scene/scene.tsx | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/client/src/templates/Challenges/components/scene/scene.tsx b/client/src/templates/Challenges/components/scene/scene.tsx index 79fe29999be..d9d85cbc778 100644 --- a/client/src/templates/Challenges/components/scene/scene.tsx +++ b/client/src/templates/Challenges/components/scene/scene.tsx @@ -13,6 +13,10 @@ const sToMs = (n: number) => { return n * 1000; }; +const loadImage = (src: string | null) => { + if (src) new Image().src = src; +}; + export function Scene({ scene, isPlaying, @@ -25,27 +29,20 @@ export function Scene({ const { t } = useTranslation(); const { setup, commands } = scene; const { audio, alwaysShowDialogue } = setup; - const { startTimestamp, finishTimestamp } = audio; + const { startTimestamp = null, finishTimestamp = null } = audio; - const audioTimestamp = - startTimestamp !== null && finishTimestamp !== null - ? `#t=${startTimestamp}` - : ''; - - const hasTimestamps = startTimestamp && finishTimestamp; - // if there are timestamps, we use the difference between them as the duration - // if not, we assume we're playing the whole audio file. - const duration = hasTimestamps - ? sToMs(finishTimestamp - startTimestamp) - : Infinity; + const hasTimestamps = startTimestamp !== null && finishTimestamp !== null; + const audioTimestamp = hasTimestamps ? `#t=${startTimestamp}` : ''; const audioRef = useRef( new Audio(`${sounds}/${audio.filename}${audioTimestamp}`) ); - const loadImage = (src: string | null) => { - if (src) new Image().src = src; - }; + // if there are timestamps, we use the difference between them as the duration + // if not, we assume we're playing the whole audio file. + const duration = hasTimestamps + ? sToMs(finishTimestamp - startTimestamp) + : Infinity; // on mount useEffect(() => {