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