mirror of
https://github.com/mempool/mempool.git
synced 2025-01-09 06:59:42 +01:00
4cbf2e0eb4
* Turn down that racket *shakes cane* * Maybe a little lower * Maybe 80%? * 70? * 30 ok? * 65 sounds best
30 lines
691 B
TypeScript
30 lines
691 B
TypeScript
import { Injectable } from '@angular/core';
|
|
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class AudioService {
|
|
audio: HTMLAudioElement;
|
|
isPlaying = false;
|
|
|
|
constructor() {
|
|
try {
|
|
this.audio = new Audio();
|
|
} catch (e) {}
|
|
}
|
|
|
|
public playSound(name: 'magic' | 'chime' | 'cha-ching' | 'bright-harmony') {
|
|
if (this.isPlaying || !this.audio) {
|
|
return;
|
|
}
|
|
this.isPlaying = true;
|
|
this.audio.src = '../../../resources/sounds/' + name + '.mp3';
|
|
this.audio.load();
|
|
this.audio.volume = 0.65; // 65% volume
|
|
this.audio.play().catch((e) => {
|
|
console.log('Play sound failed' + e);
|
|
});
|
|
setTimeout(() => this.isPlaying = false, 100);
|
|
}
|
|
}
|