在我的音乐应用中,我有一个"点击"发出http请求并从服务器播放.mp3文件的函数。我的问题是,有时候应用程序从服务器加载音频需要一段时间,这就是为什么我添加了一个离子微调器。我试图这样做,当音乐加载到this.media.load();
时,离子旋转器被显示,当它完成加载时,微调器被隐藏。
我不知道生病是否需要实施听众
Home.html中
<ion-card-content (click)="play(sound)">
<div class="wrapper">
<ion-spinner class="color-green" name="bubble"></ion-spinner>
<img src="{{ sound.imageUrl }}" />
</div>
</ion-card-content>
Home.ts
/* Plays a sound, pausing other playing sounds if necessary */
play(sound) {
console.log(sound)
if(this.media) {
this.media.pause();
}
this.media = new Audio(sound.file);
this.media.load();
this.media.play();
}
答案 0 :(得分:2)
您需要向您的微调器添加*ngIf
<ion-spinner class="color-green" name="bubble" *ngIf="showSpinner"></ion-spinner>
然后是.ts
文件
showSpinner:boolean;
...
// On the click action set to true
this.showSpinner = true;
// When the http returns with the audio file set to false
this.showSpinner = false;