<script type="text/javascript">
function random_playlist(){
var myrandom=Math.round(Math.random()*4);
var soundurl='http://ift.tt/1E3blXn';
if (myrandom==0){soundurl='http://path_to.mp3';}
else if (myrandom==1){soundurl='http://path_to.mp3';}
else if (myrandom==2){soundurl='http://path_to.mp3';}
else if (myrandom==3){soundurl='http://path_to.mp3';}
else if (myrandom==4){soundurl='http://path_to.mp3';}
console.log(soundurl);
return soundurl;
};
</script>
<audio id="audioplayer_id" controls="controls" loop>
<source id="source_id" src="" type="audio/mp3"/>
Your browser does not support the audio element
</audio>
<script type="text/javascript">
var audioload = random_playlist();
console.log(audioload);
document.getElementById('source_id').src= audioload;
var audioplayer_id = document.getElementById('audioplayer_id')
audioplayer_id.volume = 0.15;
audioplayer_id.load();
audioplayer_id.play();
</script>
Works well for me but can it be optimized or is this OK ?
I just hacked this together from various sources seems like html5 didnt integrate a playlist function in the audio tag, which seems funny to me. greets
Aucun commentaire:
Enregistrer un commentaire