HTML5 audio element with dynamic source

后端 未结 4 1825
無奈伤痛
無奈伤痛 2020-12-06 07:11

I have a basic audio player:

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-06 07:14

    I think the problem is that you need to make a request once the current song finished, you can achieve this adding the ended event listener to the audio element:

    HTML

    
    

    Javascript

    var audio = $("#player");
    audio.addEventListener("ended", function(){
        $.post("song.php", function(result){
            audio.src = result;
            audio.pause();
            audio.load();//suspends and restores all audio element
            audio.play();
        });
    });
    

    Note: If you still have problems, include the PHP code in the question and check if your PHP file is getting the proper header

提交回复
热议问题