更改另一首歌曲时如何“停止”上一首歌曲

时间:2019-07-30 21:16:58

标签: javascript wavesurfer.js

在Laravel上,我为waveurfer创建了一个脚本,当我们想播放另一首歌曲时,我想自动停止上一首歌曲 歌曲。

 <div id="waveform_infos_{{ $blog->id}}">


 <div><button class="btn btn-outline-secondary btn-sm mt-5" 
 onclick="wavesurfer_{{ $blog->id}}.playPause(this,{{ $blog->id}})"> 
 <i class="glyphicon glyphicon-play"></i>Play/Pause</button></di>


<div id="waveform_{{ $blog->id}}" style="width:350px;" ></div>


</div>

当更改为另一首歌曲时,如何使上一首歌曲停止播放?

<script>

 // Songs list//
 var aSongs = ['audio/{{ $blog->title}}.mp3'];
 var iCurrentSong = -1;



  // Waveform//
  var wavesurfer_{{ $blog->id}} = WaveSurfer.create({
  container: '#waveform_{{ $blog->id}}',
  waveColor: 'rgba(171, 153, 247, 0.79)',
  progressColor: '#625162',
  cursorWidth: 0,
  });

 // Array Songs //
var aWaves = [wavesurfer_{{ $blog->id}}];
for (i = 0; i < aWaves.length; i++) {
aWaves[i].load(aSongs[i]);



  // Play//
 aWaves[i].on('finish', function() {
 var btns = document.querySelectorAll('[.btn="play"]');
 for (i = 0; i < btns.length; i++) {
 btns[i].innerText = 'Play';
  }

 });

}

</script>

</html>

Added a new script for stop automatically a song when change another song

0 个答案:

没有答案