【发布时间】:2013-11-26 20:26:16
【问题描述】:
我正在寻找一张图片,当点击该图片时,它会播放一个声音片段(来自声音片段列表)而不重复相同的片段(直到用户浏览整个声音列表。)
目前我的代码可以正常运行,但会随机播放我的任何一个声音片段并重复很多次。
如果有人知道如何调整它以使其在重复之前至少播放列表中的每个剪辑一次,那就太棒了!
这是我目前正在使用的代码:
<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() 部分有关?
【问题讨论】:
标签: javascript playsound