| @@ -7,12 +7,14 @@ export class AlarmSoundService { | |||
| private alertInterval: any; | |||
| private alertDuration: number = 10000; | |||
| private audio = new Audio(); | |||
| isPlay = false; | |||
| constructor() { | |||
| this.audio.src = 'assets/sound/alarm_5m.mp3'; | |||
| this.audio.load(); | |||
| } | |||
| playSound(): void { | |||
| this.isPlay = true; | |||
| this.audio.play().catch((error) => { | |||
| console.error('Error playing audio:', error); | |||
| }); | |||
| @@ -31,7 +33,7 @@ export class AlarmSoundService { | |||
| state1: boolean, | |||
| state2: boolean, | |||
| ): void { | |||
| if (state5 && isReady && (state1 || state2)) { | |||
| if (state5 && isReady && (state1 || state2) && !this.isPlay) { | |||
| this.playSound(); | |||
| this.alertInterval = setInterval(() => { | |||
| this.stopAlarm(); | |||
| @@ -42,6 +44,7 @@ export class AlarmSoundService { | |||
| stopAlarm(): void { | |||
| this.stopSound(); | |||
| clearInterval(this.alertInterval); | |||
| this.isPlay = false; | |||
| } | |||
| simulateClick(element: HTMLElement) { | |||