3

我无法弄清楚如何强制 Jplayer 从动态的 asp.net 自由列表中读取歌曲?

目前我有这个用于从数据库中获取歌曲列表:

<div class="jp-playlist">
<ul><asp:Literal ID="ltRadio" runat="server" /></ul>
</div>

以下来自JPlayer的代码演示了如何将硬编码的歌曲添加到播放列表:

$(document).ready(function () {

new jPlayerPlaylist({
     jPlayer: "#jquery_jplayer",
     cssSelectorAncestor: "#jp_container_1"
}, [
{
   title: "Cro Magnon Man",
   mp3: "http://www.jplayer.org/audio/mp3/TSP-01-Cro_magnon_man.mp3",
   oga: "http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
}
], {
     swfPath: "js",
     supplied: "oga, mp3",
     wmode: "window"
});
}); 

问题是如何将“文字”列表中的歌曲添加到播放列表中?

4

2 回答 2

0

好在终于解决了问题。我正在将 JSON 转换为不需要的字符串。

相反,我循环遍历 JSon Object 数组并将其添加到播放列表中。

/*Create an empty JSon array*/ 
var jsonobj = [];

/*Loop through a given list and push it into a JSon array*/
jQuery('ul.RadioList li a').each(function (index) {
       var mp3 = jsonobj.push({ 'mp3': jQuery(this).attr('href') });
       var title = [];
       title.push(jQuery(this).text());
       jsonobj[mp3 - 1]['title'] = title;
});

var cssSelector = {
       jPlayer: "#jquery_jplayer",
       cssSelectorAncestor: "#jp_container_1"
};
/*An Empty Playlist*/
var playlist = []; 
   var options = {
       swfPath: "./js",
       supplied: "mp3"
};
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
/*Loop through the JSon array and add it to the playlist*/ 
for (i = 0; i < jsonobj.length; i++) {
      myPlaylist.add(jsonobj[i]);
}
于 2013-04-03T13:31:31.027 回答
0

你可以简单地做

myPlaylist = new jPlayerPlaylist({
        jPlayer: "#mediaPlayer",
        cssSelectorAncestor: "#jp_container"
    }, playList //JSON object
    , {
        swfPath: "dist/jplayer",
        supplied: "webmv, ogv, m4v, oga, mp3",
        useStateClassSkin: true
    });

你的 JSON 对象可以是以下元素的集合

playList.push(
          {
            'm4v': fileURL,
             'title': "File Title,
          }
);
于 2015-09-25T14:46:04.747 回答