Is a jquery callback available after .play() when using <audio>?

前端 未结 4 1365
死守一世寂寞
死守一世寂寞 2020-12-20 03:49

Guys how do I play an mp3 file and then another once the first has finished?

I have tried the following without success..

$(\'#file1)[0].play( functi         


        
4条回答
  •  遥遥无期
    2020-12-20 04:05

    I used @blasteralfred's code to create a function to play a indefinite series of sound files using jQuery:

    function playSounds(soundFileIds) {
      if (soundFileIds instanceof Array) {
        var soundFileId = soundFileIds.shift();
        playSound(soundFileId);
        $(soundFileId).bind('ended', function() {
          playSounds(soundFileIds);
        });
      } else {
        playSound(soundFileIds);
      }
    }
    

    The conditional test for an array allows me to backport this to my existing code that calls this function with just a string. Thanks!

提交回复
热议问题