HTML5/jQuery音频随机播放onClick [英] HTML5/jQuery audio shuffle onClick
问题描述
我有一个简单的HTML5音频播放列表,我希望用户单击随机播放"按钮并随机播放音频,但是我不知道执行此操作的最佳方法.我正在将 audio.js 用于HTML5音频.
I have a simple HTML5 audio playlist and I would like the user to click a "shuffle" button and shuffle the audio but I don't know the best way to go about this. I'm using audio.js for HTML5 audio.
正如您在小提琴中看到的那样,audio.js抓住<li>
内的<a>
标签以在顶部的播放器中播放音频文件.随机播放按钮需要在点击时随机选择一个<li a>
.
As you can see in the fiddle, audio.js grabs the <a>
tag inside the <li>
to play an audio file in the player at the top. The shuffle button would need to pick a random <li a>
on click.
任何帮助将不胜感激!谢谢!
Any help would be greatly appreciated! Thank you!
推荐答案
以下是随机播放按钮的逻辑.您必须编写代码才能获得播放的轨迹,但这并不难.我在ul中添加了一个名为"tracks"的类.
Here is the logic for shuffle button. You'll have to write in the code to the get the track to play but it shouldn't be that difficult. I added a class to the ul called "tracks".
$(".shufflebutton").click(function() {
var trackCount = $(".tracks li").length;
console.log('trackCount:' + trackCount);
/* Pick random number between 1 and trackCount */
var randomNum = Math.ceil(Math.random()*trackCount);
console.log("randomNum:" + randomNum);
});
完整的代码示例在这里: http://jsfiddle.net/F8w8r/
Full code example here: http://jsfiddle.net/F8w8r/
这篇关于HTML5/jQuery音频随机播放onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!