2012-11-09 69 views
0

我的jplayer腳本有問題。我需要jplayer播放由json文件構建的播放列表。下面是一個軌道的示例json輸出:從外部JSON填充JPlayer播放列表:沒有結果

{ 
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"}, 
    } 
     ] 
    } 
} 

這是我的腳本,它應該填充播放列表,但它不起作用。現在它複製所有數據,但我希望它只能得到標題,圖像和音頻網址。

<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> 

任何幫助將不勝感激。由於

回答

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 
     }); 
    }) 
});