mempool/frontend/src/app/services/audio.service.ts
Jonathan Underwood 4cbf2e0eb4
Lower volume for sound effects (#385)
* Turn down that racket *shakes cane*

* Maybe a little lower

* Maybe 80%?

* 70?

* 30 ok?

* 65 sounds best
2021-03-12 13:20:40 +07:00

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);
}
}