Javascript 在爱奥尼亚2的不同祈祷时间播放声音

Javascript 在爱奥尼亚2的不同祈祷时间播放声音,javascript,angular,ionic2,Javascript,Angular,Ionic2,我想在我的ionic2应用程序中播放在db中保存的不同祈祷时间的声音 e、 g 在这里,我在开始一个div时播放音乐,如: 在Html中 <div item-right *ngIf="playAudio"> <audio controls autoplay="true"> <source [src]="this.audio"> </audio> </div> 在我的ts文件中: se

我想在我的ionic2应用程序中播放在db中保存的不同祈祷时间的声音 e、 g

在这里,我在开始一个div时播放音乐,如: 在Html中

<div item-right *ngIf="playAudio">
      <audio controls autoplay="true">
        <source [src]="this.audio">
      </audio>
</div>

在我的ts文件中:

    setInterval(() => {
          var d = new Date();
          var hours = d.getHours();
          var min = d.getMinutes();
          var minutes;
          if (min < 10) {
            minutes = "0" + min;
            this.time = hours + ":" + minutes;
          } else {
            this.time = hours + ":" + min;
          }
          if (this.showPrayerTimes == true) {
            this.checkprayerTime();
          }
        }, 60000)

 checkprayerTime() {

    if (this.time == this.prayerTime.FajarTime) {
      this.playAudio= true;
    }
    else if (this.time == this.prayerTime.DhuhrTime) {
      this.playAudio= true;
    }
    else if (this.time == this.prayerTime.AsrTime) {
      this.playAudio= true;
    }

    else if (this.time == this.prayerTime.MaghribTime) {
      this.playAudio= true;
    }
    else if (this.time == this.prayerTime.IshaTime) {
      this.playAudio= true;
    }
    else if (this.time == this.prayerTime.JumuahTime) {
      this.playAudio= true;
    }
    else {
      console.log("time do not match");
    }
  }
setInterval(()=>{
var d=新日期();
var hours=d.getHours();
var min=d.getMinutes();
var分钟;
如果(最小值<10){
分钟=“0”+分钟;
this.time=小时+“:”+分钟;
}否则{
this.time=hours+“:”+min;
}
if(this.showPrayerTimes==true){
这个;
}
}, 60000)
检查时间(){
if(this.time==this.prayerTime.FajarTime){
这个.playAudio=true;
}
else if(this.time==this.prayerTime.DhuhrTime){
这个.playAudio=true;
}
else if(this.time==this.prayerTime.AsrTime){
这个.playAudio=true;
}
else if(this.time==this.prairtime.MaghribTime){
这个.playAudio=true;
}
else if(this.time==this.prayerTime.IshaTime){
这个.playAudio=true;
}
else if(this.time==this.prayerTime.JumuahTime){
这个.playAudio=true;
}
否则{
console.log(“时间不匹配”);
}
}
它在当前页面中工作(仅当我们在该页面上时),但是如果我想在我的应用程序中检查祈祷时间,无论我在哪个页面,它都会检查并播放音频。
提前感谢

您可以创建单独的组件用于检查和播放,并将该组件添加到应用程序顶部。
(一种全局页眉/页脚组件)

您可以创建单独的组件用于检查和播放,并将该组件添加到应用程序顶部。
(全局页眉/页脚组件的类型)

在我的应用程序组件中。ts我使用了设置间隔功能,它在完整的应用程序中运行,在我的应用程序中作为后台进程工作,无论我在哪一页播放声音。

在我的应用程序组件中。ts我使用了设置间隔功能,它在完整的应用程序中运行,在我的应用程序中作为后台进程工作,无论我在哪一页播放声音第页我是。

我的祈祷时间因不同清真寺的祈祷时间表不同而不同,那么我将如何向该组件发送祈祷时间数据我们的组件可以直接访问数据我们可以在组件上创建事件处理程序来接收更改的数据我们的自定义事件并收听组件谢谢!如果我在启动时在我的应用程序的生命周期挂钩上启动它怎么办?setinterval功能将检查计时并播放音频???我的祈祷时间因不同清真寺的祈祷时间表不同而不同,那么我将如何向该组件发送祈祷时间数据我们的组件可以直接访问数据我们可以在组件上创建事件处理程序以接收更改的数据我们的自定义事件并在组件中侦听谢谢!如果我在启动时在应用程序的生命周期挂钩上启动它,setinterval功能将检查计时并播放音频,该怎么办???