cleanup sounds that are done playing

This commit is contained in:
Joeri Exelmans 2025-10-26 12:54:02 +01:00
parent 08dc096792
commit 25fbb26fd7
2 changed files with 4 additions and 1 deletions

View file

@ -36,6 +36,9 @@ export function useAudioContext(speed: number) {
src.loop = loop;
src.start();
setSounds(sounds => [...sounds, src]);
src.addEventListener("ended", () => {
setSounds(sounds => sounds.filter(s => s !== src));
})
return src;
});
// return callback to stop playing