html - Play one of a set of audio clips randomly? -


so i'm trying setup web-page when open it, play random piece of music, , when 1 finishes, play directly after constant stream of music, not in same order every time. if goes outside bounds of html , i'm looking @ instance javascipt that's fine.

i know rather easy solution, i'm new html , trying understand better.

thanks in advance if don't soon!

this best solved using javascript, used add behavior website. html used structure site.

we can collection of audio elements queryselectorall function. find random element next line , call play method.

var audio = document.queryselectorall("audio");  function playrandom() {     audio[math.floor(math.random() * audio.length)].play() }(); 

for second part of question, want listen ended event. inside event listener function, call playrandom() function.

audio.addeventlistener("ended", function() {     playrandom(); }); 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -