0

我的 jplayer 脚本有问题。我需要 jplayer 播放从 json 文件构建的播放列表。这是一个带有一条轨道的示例 json 输出:

{
data: {

  tracks:[
    {
    id: 8678,

    title: "Show Me",

    slug: "show-me",

    url:{youtube: "",buy: ""},

    audio:[{url: "track1.mp3",format_name: "MP3",mime_type: "audio/mpeg",}],

    image:{original: "https://d25jn4u0zlr7r6.cloudfront.net/album/8/8/iroking_tP08851bc807e123178fd1e33d98.jpg"},
     }
        ]
     }
}

这是我应该填充播放列表的脚本,但它不起作用。现在它会复制所有数据,但我希望它只获取标题、图像和音频 url。

<script type="text/javascript">
$(document).ready(function(){
var cssSelector = {
    jPlayer: "#jquery_jplayer_1", 
    cssSelectorAncestor: "#jp_container_1"
};
var playlist = []; // Empty playlist
};
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
$.getJSON("https://api.server.com/2/radio/6/tracks?key=********************",

function(data){  // get the JSON array
    $.each(data,function(index,value){
        myPlaylist.add(value); // add each element in data in myPlaylist
    })
}); 
});
</script>

任何帮助将不胜感激。谢谢

4

1 回答 1

0

您需要更改此代码

$.getJSON("https://api.server.com/2/radio/6/tracks?key=********************",

function(data){  // get the JSON array
    $.each(data,function(index,value){
        myPlaylist.add(value); // add each element in data in myPlaylist
    })
}); 

到这个代码

$.getJSON("https://api.server.com/2/radio/6/tracks?key=********************",

function(data){  // get the JSON array
    $.each(data['data'].tracks, function(index,value){
        myPlaylist.add({
            title: value.title,
            artist: value.slug,
            mp3: value.audio[0].url,
            poster: value.image.original
        });
    })
}); 
于 2013-01-31T20:13:40.537 回答