【问题标题】:Track currentTime with Audio file in Progress bar/element (Angular 4)使用进度条/元素中的音频文件跟踪 currentTime(Angular 4)
【发布时间】:2018-03-03 04:55:40
【问题描述】:

所以我正在制作一个音乐播放器。当用户点击一首歌曲时,我想要一个进度条来可视化当前时间在音频文件上的位置。这是我到目前为止所拥有的:

HTML (player.component.html)

<progress value="{{songTime}}" max="100"></progress>

Typescript (player.component.ts)

paused: boolean = true;
  songInfo: any = "lol";
  songFile: any = "";
  songTime: any = "";
  audio = new Audio();

  playSong(){
    this.audio.src = this.songFile;
    this.audio.play();
    this.songTime = this.audio.currentTime;
    console.log(this.songTime)
    this.paused = false;
  }

此 console.log 返回值 0,即您开始每首歌曲的当前时间。

我想,我想,随着歌曲的进展动态地改变这个值,并让它在进度条中直观地反映出来。

【问题讨论】:

    标签: angular audio progress


    【解决方案1】:

    您只需向音频播放器添加一个timeupdate 事件监听器。

    this.audio.addEventListener("timeupdate", (currentTime)=>{
    // Code to update progress bar goes here
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-17
      • 2011-10-29
      相关资源
      最近更新 更多