我正在使用jPlayer为我的网站制作音乐播放器。
我想要的是在某处托管一个JSON文件来存储曲目标题和文件名。通过单击不同的按钮来加载不同的播放列表。
这是JSON本身:
{"tracks":[
{
"title": "Some Track 1",
"trackname": "Some_track_name_1"
},
{
"title": "Some Track 2",
"trackname": "Some_track_name_2"
},
{
"title": "Some Track 3",
"trackname": "Some_track_name_3"
}
]}
这是我的JS的想法。
$.getJSON("path/to/playlist.json",
function(....){
//Get JSON data and generate a playlist
//Playlists are generated with:
customPlaylist.add({
title: title var,
mp3: 'track path' + filename var + '.mp3' ,
});
});
创建自定义播放列表后,等待jPlayer将其设置为默认播放列表myPlaylist:
$("#Playlist_1").click(function() {
myPlaylist.setPlaylist([
set the generated playlist "customPlaylist" as the
default playlist "myPlaylist" here....
]);
这样我认为我会有多个播放列表,因此用户可以选择播放哪个播放列表。
我对JS和JSON的了解有限,所以我所拥有的只是粗略的想法。
答案 0 :(得分:1)
你正朝着正确的方向前进!
您只需使用您要回复的变量即可。轨道是一个数组,因此您可以使用forEach;
循环遍历它typedef struct Employee{
char name[MAX_SIZE];
int salary;
int experience;
} employee_t;
employee_t *readEmployee(employee_t *emp)
{
printf("Please enter Employee's name:(max 19 chars)");
scanf("%s", emp->name); // -> operator
printf("Please enter Employee's salary:");
scanf("%d", &emp->salary); // %d
printf("Please enter Employee's experience:");
scanf("%d",&emp->experience);
return emp;
}
int main(void) {
employee_t *newEmployee, tmp; // newEmployee is now a pointer
newEmployee = readEmployee( &tmp ); // newEmployee now points to tmp
printf("Employee name is %s, salary is %d, experience is %d years\n", newEmployee->name, newEmployee->salary, newEmployee->experience);
return 0;
}