Browse Source

refactor

pull/14/head
Trung Nguyen 1 year ago
parent
commit
0e8103d8e8
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      src/app/shared/services/alarm-sound.service.ts

+ 4
- 1
src/app/shared/services/alarm-sound.service.ts View File

private alertInterval: any; private alertInterval: any;
private alertDuration: number = 10000; private alertDuration: number = 10000;
private audio = new Audio(); private audio = new Audio();
isPlay = false;
constructor() { constructor() {
this.audio.src = 'assets/sound/alarm_5m.mp3'; this.audio.src = 'assets/sound/alarm_5m.mp3';
this.audio.load(); this.audio.load();
} }


playSound(): void { playSound(): void {
this.isPlay = true;
this.audio.play().catch((error) => { this.audio.play().catch((error) => {
console.error('Error playing audio:', error); console.error('Error playing audio:', error);
}); });
state1: boolean, state1: boolean,
state2: boolean, state2: boolean,
): void { ): void {
if (state5 && isReady && (state1 || state2)) {
if (state5 && isReady && (state1 || state2) && !this.isPlay) {
this.playSound(); this.playSound();
this.alertInterval = setInterval(() => { this.alertInterval = setInterval(() => {
this.stopAlarm(); this.stopAlarm();
stopAlarm(): void { stopAlarm(): void {
this.stopSound(); this.stopSound();
clearInterval(this.alertInterval); clearInterval(this.alertInterval);
this.isPlay = false;
} }


simulateClick(element: HTMLElement) { simulateClick(element: HTMLElement) {

Loading…
Cancel
Save