我有一个PHP在目录中创建一个mp3文件的JSON数组.PHP的JSON数组输出是:
[{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}]
Run Code Online (Sandbox Code Playgroud)
很好,它似乎是JQuery.jPlayer所期望的.
现在在一个基本的jplayer.js文件中,我有:
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
}, [
//I guess my JSON array should come here
// but no idea on how I put it in...
], {
swfPath: "../js",
supplied: "mp3",
wmode: "window"
});
});
Run Code Online (Sandbox Code Playgroud)
我的问题是我不能把我的JSON数组放在它应该的位置(参见js代码中的注释)
任何帮助将非常感谢!原谅我的英语,这不是我的母语,提前谢谢
大家好,对于那些有兴趣的人,我找到了一个解决方案:我的JS文件是:
$(document).ready(function(){
var cssSelector = {
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
};
var playlist = []; // Empty playlist
var options = {
swfPath: "./js",
supplied: "mp3"
};
var myPlaylist = new jPlayerPlaylist(cssSelector, playlist, options);
$.getJSON("../PHP/radio.php",function(data){ // get the JSON array produced by my PHP
$.each(data,function(index,value){
myPlaylist.add(value); // add each element in data in myPlaylist
})
});
});
Run Code Online (Sandbox Code Playgroud)
你为什么不直接输入 javascript:
var playlist = [{"title":"Kalimba","mp3":"/path/to/mydirectory/Kalimba.mp3"},{"title":"Maid with the Flaxen Hair","mp3":"/path/to/mydirectory/Maid with the Flaxen Hair.mp3"},{"title":"Sleep Away","mp3":"/path/to/mydirectory/Sleep Away.mp3"}];
$(document).ready(function(){
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},
playlist,
{
swfPath: "../js",
supplied: "mp3",
wmode: "window"
});
});
Run Code Online (Sandbox Code Playgroud)
您甚至可以使用 PHP 来生成您的playlistvar。