我正在使用jPlayer插入。这是一个例子link [ jsfiddle ] 。我只想从单个轨道编号开始播放列表,我的意思是,如果播放列表中有 5/10 首轨道,那么我想从开始时的 2/5 轨道编号开始播放列表。
最佳答案
您需要稍微修改一下 play()
方法,以便随机选择要播放的歌曲。
找到下面的代码,这是对您的 fiddlejs 的更新
var myPlayer = new jPlayerPlaylist( /* give your params here as you were doing */);
// Clonning current play() method behavior
myPlayer._play = myPlayer.play;
// Modifying default behavior of current play() method which generates
// a random song index if not provided
myPlayer.play = function(songIdx){
if (!songIdx)
songIdx = Math.floor(Math.random() * this.playlist.length);
this._play(songIdx);
console.log('Playing song #', songIdx);
}
关于javascript - 如何在开始时播放播放列表中的单个轨道编号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31361302/