Skip to content

Commit

Permalink
Issueid #231942 feat: audio delay right after completing level in pra…
Browse files Browse the repository at this point in the history
…ctice
  • Loading branch information
ajinkyapandetekdi committed Dec 17, 2024
1 parent 783b5e1 commit f324858
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/views/Practice/Practice.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,32 @@ const Practice = () => {
}
}, [startShowCase]);

const [audioSrc, setAudioSrc] = useState(null);

useEffect(() => {
const preloadAudio = async () => {
try {
const response = await fetch(LevelCompleteAudio);
const audioBlob = await response.blob();
const audioUrl = URL.createObjectURL(audioBlob);
setAudioSrc(audioUrl);
} catch (error) {
console.error("Error loading audio:", error);
}
};
preloadAudio();
}, []);

const callConfettiAndPlay = () => {
let audio = new Audio(LevelCompleteAudio);
audio.play();
if (audioSrc) {
// Play preloaded audio if available
const audio = new Audio(audioSrc);
audio.play();
} else {
// Fallback to LevelCompleteAudio if preloaded audio is not available
const fallbackAudio = new Audio(LevelCompleteAudio);
fallbackAudio.play();
}
callConfetti();
};

Expand Down

0 comments on commit f324858

Please sign in to comment.