fix : audio play
This commit is contained in:
@@ -317,11 +317,10 @@ export const getCapturedPieces = (
|
||||
new RegExp(piece, "g")
|
||||
)?.length;
|
||||
const newPiece = pieceFenToSymbol[piece] ?? piece;
|
||||
if (!count) return { piece: newPiece, count };
|
||||
|
||||
return {
|
||||
piece: newPiece,
|
||||
count: count - (piecesLeftCount ?? 0),
|
||||
count: Math.max(0, count - (piecesLeftCount ?? 0)),
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import { Move } from "chess.js";
|
||||
import { getWhoIsCheckmated, isCheck } from "./chess";
|
||||
|
||||
let audioContext: AudioContext | null = null;
|
||||
let audio: HTMLAudioElement | null = null;
|
||||
|
||||
const playSound = async (url: string) => {
|
||||
if (!audio) audio = new Audio();
|
||||
if (!audio) {
|
||||
audioContext = new AudioContext();
|
||||
audio = new Audio();
|
||||
const source = audioContext.createMediaElementSource(audio);
|
||||
source.connect(audioContext.destination);
|
||||
}
|
||||
|
||||
audio.src = url;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user