20 lines
465 B
JavaScript
20 lines
465 B
JavaScript
|
class SoundManager {
|
||
|
constructor(soundSource) {
|
||
|
this.soundSource = soundSource;
|
||
|
this.sound = new Audio(this.soundSource);
|
||
|
this.lastPlayed = 0;
|
||
|
}
|
||
|
|
||
|
play() {
|
||
|
if (Date.now() - this.lastPlayed < 50)
|
||
|
return;
|
||
|
|
||
|
const node = this.sound.cloneNode();
|
||
|
node.play();
|
||
|
setTimeout(() => {
|
||
|
node.remove();
|
||
|
}, this.sound.duration * 1000);
|
||
|
this.lastPlayed = Date.now();
|
||
|
}
|
||
|
}
|