如何将歌曲添加到jPlayer播放列表的开头

How to add a song to the beginning of a jPlayer playlist?

本文关键字:jPlayer 播放列表 开头 添加      更新时间:2023-09-26

我正在制作一个使用jPlayer播放列表的网站。我需要使用一个函数将歌曲添加到播放列表的开头(或索引),但我看到的唯一添加函数是将歌曲添加到播放列表的末尾。

根据他们的网站,他们的add函数是

add(media:Object, [playNow:Boolean]) : Void
Add a media item to the end of the playlist. Optional playNow param to start it playing after adding it.

我没有看到任何支持添加到播放列表的开始。什么好主意吗?

找到答案了。:)你可以获取当前播放列表的副本,在列表的开始添加一个新的播放列表项目,并再次重置播放列表:

var myPlaylist = new jPlayerPlaylist({...});
var tempPlaylistItems = myPlaylist.playlist;
myPlaylist.setPlaylist(tempPlaylistItems.unshift({title: "blah", artist: "blah", mp3: "blah", oga: "blah", poster: "blah"}));

你可以在最后添加你的媒体,并使用这个方法播放它:myPlaylist.play(-1);

    $("#add-new-song").click(function() {
    myPlaylist.add({
        title:"Hidden",
        artist:"Miaow",
        free: true,
        mp3:"g/audio/mp3/Miaow-02-Hidden.mp3",
        oga:"/audio/ogg/Miaow-02-Hidden.ogg",
        poster: "/audio/poster/Miaow_640x360.png"
    });
    myPlaylist.play(-1);
});