How can you create an auto playlist with the HTML5 Audio tag?

∥☆過路亽.° 提交于 2019-12-03 21:31:01
shanabus

Check out this post: using jquery + <audio> w/ php/mysql to loop playback times

var sfx = new Audio('sfx.wav');
var sounds = a.addTextTrack('metadata');

// add sounds we care about
sounds.addCue(new TextTrackCue('dog bark', 12.783, 13.612, '', '', '', true));
sounds.addCue(new TextTrackCue('kitten mew', 13.612, 15.091, '', '', '', true));

function playSound(id) {
  sfx.currentTime = sounds.getCueById(id).startTime;
  sfx.play();
}

I just updated this with a better example of using cues as specified here: http://dev.w3.org/html5/spec/Overview.html

I'm using similar code to the following on my site to play a continuous playlist of audio on my site:

<script type="text/javascript">
        var nextVideo = "/Link/To/Next/File.mp3";
        var audioPlayer = document.getElementById('audio_with_controls');
        audioPlayer.addEventListener('ended', PlayNext);

        function PlayNext() {
            audioPlayer.src = nextVideo;
            audioPlayer.play();
        }
</script>

It would be very easy for you to add an array of files that you could loop through (using arrays etc). You could also have the playlist displayed to the user, with each track being a clickable link that would call JS to change the player's "src" property.

Hope this helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!