javascript - 等待音乐加载时的 ionic 旋转器( ionic 2/Angular 2)

标签 javascript android angular typescript ionic2

在我的音乐应用程序中,我有一个“单击”功能,可以发出 http 请求并从服务器播放 .mp3 文件。我的问题是,有时应用程序需要一段时间才能从服务器加载音频,这就是我添加 ionic 旋转器的原因。我试图做到这一点,以便当音乐在 this.media.load(); 中加载时显示 ionic 旋转器,加载完成后隐藏旋转器。

我不知道是否需要实现监听器

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();
 }

最佳答案

您需要将 *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;

关于javascript - 等待音乐加载时的 ionic 旋转器( ionic 2/Angular 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43444078/

相关文章:

javascript - 解除函数绑定(bind)时遇到问题

javascript - Bookshelf.js,在 fetchAll() 方法后更新

javascript - 将列表的元组设置为 ViewData Mvc C#

android - 在 django 服务器中使用 android 应用程序进行身份验证

android - 在登录节点下的 Firebase 中保存总分

Angular 6 http 服务最佳实践

javascript - 我如何使用 jest 在 vuejs 中测试计算属性?

android - 如何将绝对坐标应用于 View 内的对象?

解析不同参数对象的Javascript泛型方法

javascript - 尝试调用方法时 ViewChild 组件未定义