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

@@ -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) {

Loading…
Cancel
Save