2020-02-26 04:29:57 +07:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class AudioService {
|
|
|
|
audio = new Audio();
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
public playSound(name: 'magic' | 'chime' | 'cha-ching') {
|
|
|
|
try {
|
2020-05-02 16:59:14 +07:00
|
|
|
this.audio.src = '../../../resources/sounds/' + name + '.mp3';
|
2020-02-26 04:29:57 +07:00
|
|
|
this.audio.load();
|
|
|
|
this.audio.play();
|
|
|
|
} catch (e) {
|
|
|
|
console.log('Play sound failed', e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|