我正在寻找一个图像,单击该图像时播放声音剪辑(来自声音剪辑列表)而不重复相同的剪辑(直到用户浏览整个声音列表。)
目前我的代码可以工作,但会随机播放我的任何一个声音片段并重复很多次。
如果有人知道如何调整它以使其在重复之前至少播放列表中的每个剪辑一次,那就太棒了!
这是我目前正在使用的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script>
function playSounds() {
var sounds = [
"AUDIO URL",
"AUDIO URL",
"AUDIO URL",
"AUDIO URL",
"AUDIO URL"
];
var index = Math.floor(Math.random() * (sounds.length));
$("#element").html("<embed src=\"" + sounds[index] + "\" hidden=\"true\" autostart=\"true\" />");
}
</script>
<a onclick="playSounds()"><img src="IMAGE URL" width="300px" id="ImageButton1"></a>
我猜这与Math.random()
代码的一部分有关?