我想在我的ionic2应用程序中播放不同的祈祷时间在db中保存的声音 例如this is my GUI
这里我正在播放音乐,打开一个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");
}
}
它正在当前页面中工作(仅当我们在此页面上时)但是如果我想在我的应用程序中查看祷告时间,无论我在哪个页面检查并播放音频。 提前致谢
答案 0 :(得分:0)
您可以创建单独的组件进行检查和播放,并将该组件添加到应用程序的顶部。 (一种全局页眉/页脚组件)
答案 1 :(得分:0)
在我的App组件中,我使用了设置间隔功能,它在完整的应用程序中运行,在我的应用程序中作为后台进程工作,无论我在哪个页面都播放声音。