2016年11月17日 星期四

Autoplay and loop audio in blogger

It is impossible to autoplay on android chrome because google's policy.
But I let the song loop from a list.
Source Code:
<audio id="audiotag1" controls autoplay preload="auto" >
<source src="http://tegos.kz/new/mp3_full/Justin_Timberlake_-_Not_A_Bad_Thing.mp3"></source>
</audio>
<script type = "text/javascript">
var idx_audio = 0
//http://musicpleer.cc/
var audio_list = [
"http://grouprbt.tom.com/files/background/20060401152833280.mp3",
"http://a.tumblr.com/tumblr_kzqo9kotQ41qaejpto1.mp3",
"http://a.tumblr.com/tumblr_l6p1x3RFEA1qzdd22o1.mp3", //mongol
"http://tegos.kz/new/mp3_full/Justin_Timberlake_-_Not_A_Bad_Thing.mp3",
];
var audio = document.getElementById("audiotag1")
audio.addEventListener('ended',function(){
audio.src = audio_list[(idx_audio++) % audio_list.length ];
audio.pause();
audio.load();
audio.play();
});
//http://stackoverflow.com/questions/21171332/play-a-list-of-audio-files-in-html
</script>


Share:

Related Posts:

0 意見:

張貼留言