简体   繁体   中英

Playing list of mp3 files one by one

I have list of mp3 files and I want them to play after the other.

I have attached my code. In between I am getting error.

function playAudio(){
  var au = document.getElementById('saveAudio');
  if($scope.listOfMp3.length > 0){
     $scope.mp3 = $scope.listOfMp3[0];
     au.src = $scope.mp3;
     var promise = au.play();
     if (promise !== undefined) {
        promise.then(function () {
          console.log('Succesfully played');
        }).catch(error => {
          console.log('Problem in playing');
          $scope.listOfMp3.shift();
          playAudio();
        });
     }
     au.addEventListener('ended',function(){
        $scope.listOfMp3.shift();
        playAudio();
     });
  } else {
     au.pause();
  }
}

要解决此问题,您应该获取歌曲的歌曲结束事件,并在该事件上传递该函数以播放下一首歌曲。

如果您有一个,您介意共享您的最终(以及工作代码或URL)吗?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM