在 pausing/resetting 其他人的同时播放选定的音频

Play selected audio while pausing/resetting others

我有两个通过按钮的点击事件播放的音频元素。如果选择了另一个,我已经成功地设法暂停了一个,但还需要将暂停的元素设置回 0.0 秒(即暂停和重置)。

我知道 Javascript 目前没有 stop() 方法,导致假设这将通过将其 currentTime 设置为 0 来完成。如果是这样,我只是无法找出将此方法合并到我的代码中的最佳方法。

现在我使用 $(".audio").trigger("pause"); 在条件的后半部分暂停 all 音频元素,这在性能方面不太有效。仅暂停和重置 之前播放的 音频文件而不是页面上的每个音频文件的最佳方法是什么?

http://jsfiddle.net/txrcxfpy/

使用下面的代码。检查 DEMO

 $(function() {    
  $('.track-button').click(function() {
    var reSet = $('.track-button').not($(this)).siblings(".audio").get(0);
    reSet.pause();
    reSet.currentTime = 0;

    var $this          = $(this),
        trackNum       = $this.text(),
        currentAudio   = $this.siblings(".audio"),
        audioIsPaused  = currentAudio.get(0).paused;

    if (audioIsPaused) {
        currentAudio.get(0).play();
    } else {
        currentAudio.get(0).pause();
    }
  });
});