fix : don't play sounds on top of each other

This commit is contained in:
GuillaumeSD
2024-03-27 01:19:47 +01:00
parent afbb89c9c5
commit c69ec73005

View File

@@ -1,8 +1,15 @@
import { Move } from "chess.js";
import { getWhoIsCheckmated, isCheck } from "./chess";
let audio: HTMLAudioElement | null = null;
const playSound = async (url: string) => {
const audio = new Audio(url);
if (!audio) audio = new Audio();
const isPlaying = !audio.paused && !audio.ended;
if (isPlaying) return;
audio.src = url;
await audio.play();
};